From f5fd8ec29548b90daf4981ae6a7dca4286aed649 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 24 Nov 2023 18:23:39 +0200 Subject: [PATCH 01/15] Removed @LazySingleton to reduce redundant build time --- .../add_new_action/add_new_action_bloc.dart | 9 ++------ .../add_new_binding/add_new_binding_bloc.dart | 8 ++----- .../add_new_routine/add_new_routine_bloc.dart | 11 ++++------ .../add_new_scene/add_new_scene_bloc.dart | 11 ++++------ .../add_user_to_home_bloc.dart | 8 +++---- lib/application/auth/auth_bloc.dart | 9 +++----- .../auth/sign_in_form/sign_in_form_bloc.dart | 11 ++++------ .../blinds_actor/blinds_actor_bloc.dart | 16 +++++++------- .../blinds_watcher/blinds_watcher_bloc.dart | 5 ++--- .../boilers_actor/boilers_actor_bloc.dart | 7 +++--- .../boilers_watcher/boilers_watcher_bloc.dart | 5 ++--- lib/application/cbj_comp/cbj_comp_bloc.dart | 10 ++++----- .../configure_new_cbj_comp_bloc.dart | 21 +++++------------- .../create_home/create_home_bloc.dart | 7 ++---- .../device_actor/device_actor_bloc.dart | 3 +-- .../device_watcher/device_watcher_bloc.dart | 5 ++--- .../folder_of_bindings_bloc.dart | 4 +--- .../folder_of_routines_bloc.dart | 4 +--- .../folders_of_bindings_bloc.dart | 5 +---- .../folders_of_routines_bloc.dart | 5 +---- .../hub_in_network/hub_in_network_bloc.dart | 11 +++++----- .../join_home_by_id/join_home_by_id_bloc.dart | 11 ++++------ .../light_toggle/light_toggle_bloc.dart | 14 +++++------- .../lights_actor/lights_actor_bloc.dart | 7 +++--- .../lights_watcher/lights_watcher_bloc.dart | 5 ++--- .../manage_access_point_bloc.dart | 9 +++----- .../manage_users/manage_users_bloc.dart | 7 ++---- .../manage_wifi/manage_wifi_bloc.dart | 9 +++----- .../more_connections_options_bloc.dart | 8 +++---- .../plus_button_settings_bloc.dart | 8 +++---- .../printers_actor/printers_actor_bloc.dart | 9 ++++---- .../printers_watcher_bloc.dart | 5 ++--- .../remote_pipes/remote_pipes_bloc.dart | 7 ++---- .../room_sign_in_form_bloc.dart | 5 ++--- .../smart_computers_actor_bloc.dart | 12 +++++----- .../smart_computer_watcher_bloc.dart | 5 ++--- .../smart_plug_toggle_bloc.dart | 11 +++++----- .../smart_plugs_actor_bloc.dart | 7 +++--- .../smart_plugs_watcher_bloc.dart | 5 ++--- .../smart_tv_actor/smart_tv_actor_bloc.dart | 22 +++++++++---------- .../smart_tv_watcher_bloc.dart | 5 ++--- .../software_info/software_info_bloc.dart | 11 ++++------ .../switch_toggle/switch_toggle_bloc.dart | 16 ++++++-------- .../switches_actor/switches_actor_bloc.dart | 13 +++++------ .../switches_watcher_bloc.dart | 5 ++--- .../user_homes_list/user_homes_list_bloc.dart | 11 +++++----- .../i_add_user_to_home_repository.dart | 11 +++++----- lib/domain/auth/i_auth_facade.dart | 9 +++++++- .../cbj_comp/i_cbj_comp_repository.dart | 11 +++++----- .../create_home/i_create_home_repository.dart | 9 +++++++- lib/domain/device/i_device_repository.dart | 9 +++++++- .../home_user/i_home_user_repository.dart | 11 +++++----- .../hub/i_hub_connection_repository.dart | 9 +++++++- .../local_db/i_local_db_repository2.dart | 13 ++++++++--- .../i_manage_network_repository.dart | 12 +++++----- .../i_remote_pipes_repository.dart | 9 +++++++- ...i_security_bear_connection_repository.dart | 9 +++++++- .../i_software_info_repository.dart | 9 +++++++- .../i_all_homes_of_user_repository.dart | 2 +- lib/domain/user/i_user_repository.dart | 11 +++++----- .../add_user_to_home_reposityory.dart | 8 ++----- .../cbj_comp/cbj_comp_repository.dart | 6 ++--- .../create_home/create_home_repository.dart | 12 +++++----- .../devices/device/device_repository.dart | 4 +--- .../home_user/home_user_repository.dart | 2 -- .../hub_auth_facade/hub_auth_facade.dart | 6 ++--- .../hub_client/hub_connection_repository.dart | 18 +++++++-------- .../hub_client/hub_requests_routing.dart | 5 ++--- .../isar_local_db/isar_repository.dart | 4 +--- .../manage_wifi/manage_wifi_repository.dart | 2 -- .../remote_pipes/remote_pipes_repository.dart | 2 -- .../security_bear_connection_repository.dart | 6 ++--- .../software_info_repository.dart | 9 +++----- lib/infrastructure/user/user_repository.dart | 10 ++++----- lib/main.dart | 2 +- .../pages/home_page/home_page.dart | 3 +-- pubspec.yaml | 2 ++ 77 files changed, 287 insertions(+), 350 deletions(-) diff --git a/lib/application/add_new_action/add_new_action_bloc.dart b/lib/application/add_new_action/add_new_action_bloc.dart index 019a77b85..cde3dff53 100644 --- a/lib/application/add_new_action/add_new_action_bloc.dart +++ b/lib/application/add_new_action/add_new_action_bloc.dart @@ -16,8 +16,7 @@ part 'add_new_action_state.dart'; @injectable class AddNewActionBloc extends Bloc { - AddNewActionBloc(this._deviceRepository) - : super(AddNewActionState.initial()) { + AddNewActionBloc() : super(AddNewActionState.initial()) { on(_changeActionDevices); on(_actionsNameChange); on(_changePropertyForDevices); @@ -26,10 +25,6 @@ class AddNewActionBloc extends Bloc { add(const AddNewActionEvent.initialized()); } - // listOfPropertiesToChange - - final IDeviceRepository _deviceRepository; - List _allRooms = []; List _allDevices = []; @@ -41,7 +36,7 @@ class AddNewActionBloc extends Bloc { _allRooms = List.from(r.iter); }); - (await _deviceRepository.getAllDevices()).fold((l) => null, (r) { + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { _allDevices = List.from(r.iter); }); _allRooms.removeWhere((element) => element == null); diff --git a/lib/application/add_new_binding/add_new_binding_bloc.dart b/lib/application/add_new_binding/add_new_binding_bloc.dart index 1fd1311d5..d1c720cdd 100644 --- a/lib/application/add_new_binding/add_new_binding_bloc.dart +++ b/lib/application/add_new_binding/add_new_binding_bloc.dart @@ -16,8 +16,7 @@ part 'add_new_binding_state.dart'; @injectable class AddNewBindingBloc extends Bloc { - AddNewBindingBloc(this._deviceRepository, this._bindingRepository) - : super(AddNewBindingState.initial()) { + AddNewBindingBloc() : super(AddNewBindingState.initial()) { on(_changeActionDevices); on(_bindingNameChange); on(_addDevicesWithNewActions); @@ -28,9 +27,6 @@ class AddNewBindingBloc extends Bloc { add(const AddNewBindingEvent.initialized()); } - final IDeviceRepository _deviceRepository; - final IBindingCbjRepository _bindingRepository; - List _allDevices = []; String bindingName = ''; @@ -48,7 +44,7 @@ class AddNewBindingBloc extends Bloc { Initialized event, Emitter emit, ) async { - (await _deviceRepository.getAllDevices()).fold((l) => null, (r) { + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { _allDevices = List.from(r.iter); }); _allDevices.removeWhere((element) => element == null); diff --git a/lib/application/add_new_routine/add_new_routine_bloc.dart b/lib/application/add_new_routine/add_new_routine_bloc.dart index 02c8a7d49..5835cadbe 100644 --- a/lib/application/add_new_routine/add_new_routine_bloc.dart +++ b/lib/application/add_new_routine/add_new_routine_bloc.dart @@ -17,8 +17,7 @@ part 'add_new_routine_state.dart'; @injectable class AddNewRoutineBloc extends Bloc { - AddNewRoutineBloc(this._deviceRepository, this._routineRepository) - : super(AddNewRoutineState.initial()) { + AddNewRoutineBloc() : super(AddNewRoutineState.initial()) { on(_addRoutineDate); on(_changeActionDevices); on(_routineNameChange); @@ -30,9 +29,6 @@ class AddNewRoutineBloc extends Bloc { add(const AddNewRoutineEvent.initialized()); } - final IDeviceRepository _deviceRepository; - final IRoutineCbjRepository _routineRepository; - List _allDevices = []; String routineName = ''; @@ -54,7 +50,7 @@ class AddNewRoutineBloc extends Bloc { Initialized event, Emitter emit, ) async { - (await _deviceRepository.getAllDevices()).fold((l) => null, (r) { + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { _allDevices = List.from(r.iter); }); _allDevices.removeWhere((element) => element == null); @@ -109,7 +105,8 @@ class AddNewRoutineBloc extends Bloc { return; } - _routineRepository.addOrUpdateNewRoutineInHubFromDevicesPropertyActionList( + IRoutineCbjRepository.instance + .addOrUpdateNewRoutineInHubFromDevicesPropertyActionList( routineName, allDevicesWithNewAction, daysToRepeat!, diff --git a/lib/application/add_new_scene/add_new_scene_bloc.dart b/lib/application/add_new_scene/add_new_scene_bloc.dart index 86fced1b0..5e1ae4402 100644 --- a/lib/application/add_new_scene/add_new_scene_bloc.dart +++ b/lib/application/add_new_scene/add_new_scene_bloc.dart @@ -17,8 +17,7 @@ part 'add_new_scene_state.dart'; @injectable class AddNewSceneBloc extends Bloc { - AddNewSceneBloc(this._deviceRepository, this._sceneRepository) - : super(AddNewSceneState.initial()) { + AddNewSceneBloc() : super(AddNewSceneState.initial()) { on(_changeActionDevices); on(_sceneNameChange); on(_addDevicesWithNewActions); @@ -29,9 +28,6 @@ class AddNewSceneBloc extends Bloc { add(const AddNewSceneEvent.initialized()); } - final IDeviceRepository _deviceRepository; - final ISceneCbjRepository _sceneRepository; - List _allDevices = []; String sceneName = ''; @@ -49,7 +45,7 @@ class AddNewSceneBloc extends Bloc { Initialized event, Emitter emit, ) async { - (await _deviceRepository.getAllDevices()).fold((l) => null, (r) { + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { _allDevices = List.from(r.iter); }); _allDevices.removeWhere((element) => element == null); @@ -88,7 +84,8 @@ class AddNewSceneBloc extends Bloc { SendSceneToHub event, Emitter emit, ) async { - _sceneRepository.addOrUpdateNewSceneInHubFromDevicesPropertyActionList( + ISceneCbjRepository.instance + .addOrUpdateNewSceneInHubFromDevicesPropertyActionList( sceneName, allDevicesWithNewAction, // TODO: Check what value to use diff --git a/lib/application/add_user_to_home/add_user_to_home_bloc.dart b/lib/application/add_user_to_home/add_user_to_home_bloc.dart index 6d4a02b2b..dea5fb46f 100644 --- a/lib/application/add_user_to_home/add_user_to_home_bloc.dart +++ b/lib/application/add_user_to_home/add_user_to_home_bloc.dart @@ -14,15 +14,12 @@ part 'add_user_to_home_state.dart'; @injectable class AddUserToHomeBloc extends Bloc { - AddUserToHomeBloc(this._addUserToHomeRepo) - : super(AddUserToHomeState.initial()) { + AddUserToHomeBloc() : super(AddUserToHomeState.initial()) { on(_emailChanged); on(_permissionChanged); on(_addUserToHomeByEmail); } - final IAddUserToHomeRepository _addUserToHomeRepo; - Future _emailChanged( EmailChanged event, Emitter emit, @@ -43,7 +40,8 @@ class AddUserToHomeBloc extends Bloc { email: HomeUserEmail(event.email), permission: HomeUserPermission('Admin'), ); - final userOption = await _addUserToHomeRepo.add(addUserHomeEntity); + final userOption = + await IAddUserToHomeRepository.instance.add(addUserHomeEntity); emit( userOption.fold( (_) => const AddUserToHomeState.addingHomeFailure(), diff --git a/lib/application/auth/auth_bloc.dart b/lib/application/auth/auth_bloc.dart index fd995759c..7e107c5fa 100644 --- a/lib/application/auth/auth_bloc.dart +++ b/lib/application/auth/auth_bloc.dart @@ -1,7 +1,6 @@ import 'package:bloc/bloc.dart'; import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -11,14 +10,12 @@ part 'auth_state.dart'; @injectable class AuthBloc extends Bloc { - AuthBloc(this._authFacade) : super(const AuthState.initial()) { + AuthBloc() : super(const AuthState.initial()) { on(_initialized); on(_authCheckRequested); on(_signedOut); } - final IAuthFacade _authFacade; - Future _initialized( Initialized event, Emitter emit, @@ -33,7 +30,7 @@ class AuthBloc extends Bloc { ) async { // For now will check only if hub connection info is saved emit( - (await getIt().getHubEntityNetworkName()).fold( + (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( (l) => const AuthState.unauthenticated(), (r) => const AuthState.authenticated(), ), @@ -50,7 +47,7 @@ class AuthBloc extends Bloc { SignedOut event, Emitter emit, ) async { - await _authFacade.signOut(); + await IAuthFacade.instance.signOut(); emit(const AuthState.unauthenticated()); } } diff --git a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart b/lib/application/auth/sign_in_form/sign_in_form_bloc.dart index 01ac5d4c9..36096057e 100644 --- a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart +++ b/lib/application/auth/sign_in_form/sign_in_form_bloc.dart @@ -14,7 +14,7 @@ part 'sign_in_form_state.dart'; @injectable class SignInFormBloc extends Bloc { - SignInFormBloc(this._authFacade) : super(SignInFormState.initial()) { + SignInFormBloc() : super(SignInFormState.initial()) { on(_emailChanged); on(_passwordChanged); on(_registerWithEmailAndPassword); @@ -22,8 +22,6 @@ class SignInFormBloc extends Bloc { on(_signInWithGooglePressed); } - final IAuthFacade _authFacade; - Future _emailChanged( EmailChanged event, Emitter emit, @@ -53,7 +51,7 @@ class SignInFormBloc extends Bloc { Emitter emit, ) async { _performActionOnAuthFacadeWithEmailAndPassword( - _authFacade.registerWithEmailAndPassword, + IAuthFacade.instance.registerWithEmailAndPassword, ).forEach((element) { emit(element); }); @@ -64,7 +62,7 @@ class SignInFormBloc extends Bloc { Emitter emit, ) async { _performActionOnAuthFacadeWithEmailAndPassword( - _authFacade.signInWithEmailAndPassword, + IAuthFacade.instance.signInWithEmailAndPassword, ).forEach((element) { emit(element); }); @@ -92,8 +90,7 @@ class SignInFormBloc extends Bloc { Future> Function({ required EmailAddress emailAddress, required Password password, - }) - forwardedCall, + }) forwardedCall, ) async* { Either? failureOrSuccess; diff --git a/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart b/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart index f1b796ebd..a134fb3ac 100644 --- a/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart +++ b/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -16,8 +16,7 @@ part 'blinds_actor_state.dart'; @injectable class BlindsActorBloc extends Bloc { - BlindsActorBloc(this._deviceRepository) - : super(const BlindsActorState.initial()) { + BlindsActorBloc() : super(const BlindsActorState.initial()) { on(_deleted); on(_initialized); on(_moveUpAllBlinds); @@ -25,8 +24,6 @@ class BlindsActorBloc extends Bloc { on(_moveDownAllBlinds); } - final IDeviceRepository _deviceRepository; - Future _deleted( Deleted event, Emitter emit, @@ -46,7 +43,8 @@ class BlindsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.moveUpStateDevices(devicesId: event.blindsIdToTurnUp); + IDeviceRepository.instance + .moveUpStateDevices(devicesId: event.blindsIdToTurnUp); } Future _stopAllBlinds( @@ -58,7 +56,8 @@ class BlindsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.stopStateDevices(devicesId: event.blindsIdToStop); + IDeviceRepository.instance + .stopStateDevices(devicesId: event.blindsIdToStop); } Future _moveDownAllBlinds( @@ -70,6 +69,7 @@ class BlindsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.moveDownStateDevices(devicesId: event.blindsIdToTurnDown); + IDeviceRepository.instance + .moveDownStateDevices(devicesId: event.blindsIdToTurnDown); } } diff --git a/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart b/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart index 4628f5ffc..cf4b28c71 100644 --- a/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart +++ b/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart @@ -16,13 +16,12 @@ part 'blinds_watcher_state.dart'; @injectable class BlindsWatcherBloc extends Bloc { - BlindsWatcherBloc(this._deviceRepository) + BlindsWatcherBloc() : super(BlindsWatcherState.initial()) { on(_watchAllStarted); on(_blindsReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -32,7 +31,7 @@ class BlindsWatcherBloc extends Bloc { ) async { emit(const BlindsWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchBlinds().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchBlinds().listen( (eventWatch) => add(BlindsWatcherEvent.blindsReceived(eventWatch)), ); } diff --git a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart b/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart index 39dd858c4..ab90073e3 100644 --- a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart +++ b/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart @@ -16,7 +16,7 @@ part 'boilers_actor_state.dart'; @injectable class BoilersActorBloc extends Bloc { - BoilersActorBloc(this._deviceRepository) + BoilersActorBloc() : super(const BoilersActorState.initial()) { on(_deleted); on(_initialized); @@ -24,7 +24,6 @@ class BoilersActorBloc extends Bloc { on(_turnOffAllBoilers); } - final IDeviceRepository _deviceRepository; Future _deleted( Deleted event, @@ -45,7 +44,7 @@ class BoilersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.boilersIdToTurnUp); + IDeviceRepository.instance.turnOnDevices(devicesId: event.boilersIdToTurnUp); } Future _turnOffAllBoilers( @@ -57,6 +56,6 @@ class BoilersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices(devicesId: event.boilersIdToTurnOff); + IDeviceRepository.instance.turnOffDevices(devicesId: event.boilersIdToTurnOff); } } diff --git a/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart b/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart index e2a623321..484b5c0f0 100644 --- a/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart +++ b/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart @@ -17,13 +17,12 @@ part 'boilers_watcher_state.dart'; @injectable class BoilersWatcherBloc extends Bloc { - BoilersWatcherBloc(this._deviceRepository) + BoilersWatcherBloc() : super(BoilersWatcherState.initial()) { on(_watchAllStarted); on(_boilersReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -33,7 +32,7 @@ class BoilersWatcherBloc ) async { emit(const BoilersWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchBoilers().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchBoilers().listen( (eventWatch) => add(BoilersWatcherEvent.boilersReceived(eventWatch)), ); } diff --git a/lib/application/cbj_comp/cbj_comp_bloc.dart b/lib/application/cbj_comp/cbj_comp_bloc.dart index f2c95ee18..e1bdb854b 100644 --- a/lib/application/cbj_comp/cbj_comp_bloc.dart +++ b/lib/application/cbj_comp/cbj_comp_bloc.dart @@ -14,7 +14,7 @@ part 'cbj_comp_state.dart'; @injectable class CBJCompBloc extends Bloc { - CBJCompBloc(this._cBJCompRepository) : super(CBJCompState.initial()) { + CBJCompBloc() : super(CBJCompState.initial()) { on(_initialized); on(_watchAllStarted); on(_changeAction); @@ -22,8 +22,6 @@ class CBJCompBloc extends Bloc { on(_create); } - final ICBJCompRepository _cBJCompRepository; - StreamSubscription>? _cbjCompStreamSubscription; @@ -43,7 +41,7 @@ class CBJCompBloc extends Bloc { ) async { emit(const CBJCompState.loadInProgress()); await _cbjCompStreamSubscription?.cancel(); - _cbjCompStreamSubscription = _cBJCompRepository + _cbjCompStreamSubscription = ICBJCompRepository.instance .getConnectedComputersIP() .listen((failureOrCBJCompList) { final dynamic failureOrCompListDynamic = failureOrCBJCompList.fold( @@ -92,7 +90,7 @@ class CBJCompBloc extends Bloc { Emitter emit, ) async { final actionResult = - await _cBJCompRepository.updateCompInfo(event.cBJCompEntity); + await ICBJCompRepository.instance.updateCompInfo(event.cBJCompEntity); emit( actionResult.fold( @@ -105,7 +103,7 @@ class CBJCompBloc extends Bloc { @override Future close() async { await _cbjCompStreamSubscription?.cancel(); - await _cBJCompRepository.shutdownServer(); + await ICBJCompRepository.instance.shutdownServer(); return super.close(); } } diff --git a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart index 6dff7d333..ccf3e7f59 100644 --- a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart +++ b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart @@ -30,11 +30,7 @@ part 'configure_new_cbj_comp_state.dart'; @injectable class ConfigureNewCbjCompBloc extends Bloc { - ConfigureNewCbjCompBloc( - this._deviceRepository, - this._cBJCompRepository, - this._securityBearConnectionRepository, - ) : super(const ConfigureNewCbjCompState.initial()) { + ConfigureNewCbjCompBloc() : super(const ConfigureNewCbjCompState.initial()) { on(_initialized); on(_deleted); on(_setupNewDevice); @@ -49,14 +45,9 @@ class ConfigureNewCbjCompBloc on(_searchIfHubOnTheSameWifiNetwork); } - final ISecurityBearConnectionRepository _securityBearConnectionRepository; - final IDeviceRepository _deviceRepository; - /// Progress counter for setting new devices double progressPercent = 0.0; - final ICBJCompRepository _cBJCompRepository; - Future _initialized( Initialized event, Emitter emit, @@ -105,7 +96,7 @@ class ConfigureNewCbjCompBloc for (final GenericLightDE device in devicesList.asList()) { final Either createInCloudResponse = - await _deviceRepository.create(device); + await IDeviceRepository.instance.create(device); createInCloudResponse.fold( (l) { @@ -174,7 +165,7 @@ class ConfigureNewCbjCompBloc final CBJCompEntity compUpdatedData = event.cBJCompEntity; final Either setSecurityBearWiFi = - await _securityBearConnectionRepository + await ISecurityBearConnectionRepository.instance .setSecurityBearWiFiInformation(compUpdatedData); setSecurityBearWiFi.fold( @@ -204,7 +195,7 @@ class ConfigureNewCbjCompBloc final CBJCompEntity compUpdatedData = event.cBJCompEntity; final Either setSecurityBearWiFi = - await _securityBearConnectionRepository + await ISecurityBearConnectionRepository.instance .setSecurityBearWiFiInformation(compUpdatedData); setSecurityBearWiFi.fold( @@ -264,7 +255,7 @@ class ConfigureNewCbjCompBloc while (true) { connectionTimeout++; - (await _securityBearConnectionRepository + (await ISecurityBearConnectionRepository.instance .searchForSecurityBearInCurrentNetwork()) .fold((l) {}, (r) { emit(const ConfigureNewCbjCompState.completeSuccess()); @@ -317,7 +308,7 @@ class ConfigureNewCbjCompBloc bool error = false; final Either updateAllDevices = - await _cBJCompRepository.firstSetup(compUpdatedData); + await ICBJCompRepository.instance.firstSetup(compUpdatedData); updateAllDevices.fold( (l) { diff --git a/lib/application/create_home/create_home_bloc.dart b/lib/application/create_home/create_home_bloc.dart index faa24acac..312c08d68 100644 --- a/lib/application/create_home/create_home_bloc.dart +++ b/lib/application/create_home/create_home_bloc.dart @@ -15,14 +15,11 @@ part 'create_home_state.dart'; @injectable class CreateHomeBloc extends Bloc { - CreateHomeBloc(this._createHomeRepository) - : super(CreateHomeState.initialized()) { + CreateHomeBloc() : super(CreateHomeState.initialized()) { on(_initialized); on(_createHome); } - final ICreateHomeRepository _createHomeRepository; - Future _initialized( Initialized event, Emitter emit, @@ -42,7 +39,7 @@ class CreateHomeBloc extends Bloc { ); final initialization = - await _createHomeRepository.createNewHome(createHomeEntity); + await ICreateHomeRepository.instance.createNewHome(createHomeEntity); emit( initialization.fold( diff --git a/lib/application/devices/device_actor/device_actor_bloc.dart b/lib/application/devices/device_actor/device_actor_bloc.dart index ce16f4cd6..61c90a55f 100644 --- a/lib/application/devices/device_actor/device_actor_bloc.dart +++ b/lib/application/devices/device_actor/device_actor_bloc.dart @@ -13,13 +13,12 @@ part 'device_actor_state.dart'; @injectable class DeviceActorBloc extends Bloc { - DeviceActorBloc(this._deviceRepository) + DeviceActorBloc() : super(const DeviceActorState.initial()) { on(_deleted); on(_initialized); } - final IDeviceRepository _deviceRepository; Future _deleted( Deleted event, diff --git a/lib/application/devices/device_watcher/device_watcher_bloc.dart b/lib/application/devices/device_watcher/device_watcher_bloc.dart index 56488d3db..03e95eb19 100644 --- a/lib/application/devices/device_watcher/device_watcher_bloc.dart +++ b/lib/application/devices/device_watcher/device_watcher_bloc.dart @@ -18,14 +18,13 @@ part 'device_watcher_state.dart'; @injectable class DeviceWatcherBloc extends Bloc { - DeviceWatcherBloc(this._deviceRepository) + DeviceWatcherBloc() : super(DeviceWatcherState.initial()) { on(_watchAllStarted); on(_roomsReceived); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; KtList listOfDevices = [null].toImmutableList(); KtList listOfRooms = [null].toImmutableList(); @@ -99,7 +98,7 @@ class DeviceWatcherBloc extends Bloc { }); _deviceStreamSubscription = - _deviceRepository.watchAllDevices().listen((eventWatch) { + IDeviceRepository.instance.watchAllDevices().listen((eventWatch) { add(DeviceWatcherEvent.devicesReceived(eventWatch)); }); } diff --git a/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart b/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart index a3bd7ba39..b4a0867e5 100644 --- a/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart +++ b/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart @@ -14,12 +14,10 @@ part 'folder_of_bindings_state.dart'; @injectable class FolderOfBindingsBloc extends Bloc { - FolderOfBindingsBloc(this._iBindingRepository) - : super(FolderOfBindingsState.initialized()) { + FolderOfBindingsBloc() : super(FolderOfBindingsState.initialized()) { on(_initialized); } - final IBindingCbjRepository _iBindingRepository; late RoomEntity folderOfBindings; List allBindingsInTheRoom = []; diff --git a/lib/application/folder_of_routines/folder_of_routines_bloc.dart b/lib/application/folder_of_routines/folder_of_routines_bloc.dart index 2eba2fe4a..8783eb3fe 100644 --- a/lib/application/folder_of_routines/folder_of_routines_bloc.dart +++ b/lib/application/folder_of_routines/folder_of_routines_bloc.dart @@ -14,12 +14,10 @@ part 'folder_of_routines_state.dart'; @injectable class FolderOfRoutinesBloc extends Bloc { - FolderOfRoutinesBloc(this._iRoutineRepository) - : super(FolderOfRoutinesState.initialized()) { + FolderOfRoutinesBloc() : super(FolderOfRoutinesState.initialized()) { on(_initialized); } - final IRoutineCbjRepository _iRoutineRepository; late RoomEntity folderOfRoutines; List allRoutinesInTheRoom = []; diff --git a/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart b/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart index 4d26cedc6..4d3faa7fb 100644 --- a/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart +++ b/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart @@ -17,13 +17,10 @@ part 'folders_of_bindings_state.dart'; @injectable class FoldersOfBindingsBloc extends Bloc { - FoldersOfBindingsBloc(this._iBindingsRepository) - : super(FoldersOfBindingsState.initialized()) { + FoldersOfBindingsBloc() : super(FoldersOfBindingsState.initialized()) { on(_initialized); } - final IBindingCbjRepository _iBindingsRepository; - List allBindings = []; List allRoomsWithBindings = []; diff --git a/lib/application/folders_of_routines/folders_of_routines_bloc.dart b/lib/application/folders_of_routines/folders_of_routines_bloc.dart index 05e0bb25e..0770bf7df 100644 --- a/lib/application/folders_of_routines/folders_of_routines_bloc.dart +++ b/lib/application/folders_of_routines/folders_of_routines_bloc.dart @@ -17,13 +17,10 @@ part 'folders_of_routines_state.dart'; @injectable class FoldersOfRoutinesBloc extends Bloc { - FoldersOfRoutinesBloc(this._iRoutinesRepository) - : super(FoldersOfRoutinesState.initialized()) { + FoldersOfRoutinesBloc() : super(FoldersOfRoutinesState.initialized()) { on(_initialized); } - final IRoutineCbjRepository _iRoutinesRepository; - List allRoutines = []; List allRoomsWithRoutines = []; diff --git a/lib/application/hub_in_network/hub_in_network_bloc.dart b/lib/application/hub_in_network/hub_in_network_bloc.dart index b826e21bd..690c98f3f 100644 --- a/lib/application/hub_in_network/hub_in_network_bloc.dart +++ b/lib/application/hub_in_network/hub_in_network_bloc.dart @@ -20,8 +20,7 @@ part 'hub_in_network_state.dart'; @injectable class HubInNetworkBloc extends Bloc { - HubInNetworkBloc(this._hubConnectionRepository) - : super(HubInNetworkState.initial()) { + HubInNetworkBloc() : super(HubInNetworkState.initial()) { on(_initialEvent); on(_searchHubInNetwork); on(_openSmartCameraPage); @@ -29,7 +28,6 @@ class HubInNetworkBloc extends Bloc { on(_isHubIpCheckBoxChangedState); } - final IHubConnectionRepository _hubConnectionRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -51,7 +49,8 @@ class HubInNetworkBloc extends Bloc { loading = true; emit(const HubInNetworkState.loadInProgress()); emit( - await (await _hubConnectionRepository.searchForHub()).fold((l) async { + await (await IHubConnectionRepository.instance.searchForHub()).fold( + (l) async { return (await _searchSmartDevices()).fold( (HubFailures l) => HubInNetworkState.loadFailure(l), (r) => HubInNetworkState.loadSuccessSecurityCamera(r), @@ -65,7 +64,7 @@ class HubInNetworkBloc extends Bloc { } Future> _searchSmartDevices() { - return _hubConnectionRepository.containsSmartDevice(); + return IHubConnectionRepository.instance.containsSmartDevice(); } Future _searchHubUsingAnyIpOnTheNetwork( @@ -74,7 +73,7 @@ class HubInNetworkBloc extends Bloc { ) async { emit(const HubInNetworkState.loadInProgress()); emit( - (await _hubConnectionRepository.searchForHub( + (await IHubConnectionRepository.instance.searchForHub( deviceIpOnTheNetwork: event.ipOnTheNetwork, isThatTheIpOfTheHub: event.isHubIp, )) diff --git a/lib/application/join_home_by_id/join_home_by_id_bloc.dart b/lib/application/join_home_by_id/join_home_by_id_bloc.dart index 22f163853..02b6c260b 100644 --- a/lib/application/join_home_by_id/join_home_by_id_bloc.dart +++ b/lib/application/join_home_by_id/join_home_by_id_bloc.dart @@ -15,14 +15,11 @@ part 'join_home_by_id_state.dart'; @injectable class JoinHomeByIdBloc extends Bloc { - JoinHomeByIdBloc(this._iUserRepository) - : super(JoinHomeByIdState.initialized()) { + JoinHomeByIdBloc() : super(JoinHomeByIdState.initialized()) { on(_initialized); on(_addHomeById); } - final IUserRepository _iUserRepository; - Future _initialized( Initialized event, Emitter emit, @@ -39,8 +36,8 @@ class JoinHomeByIdBloc extends Bloc { ) async { emit(const JoinHomeByIdState.loading()); - final getCurrentUser = - (await _iUserRepository.getCurrentUser()).fold((l) => null, (r) => r); + final getCurrentUser = (await IUserRepository.instance.getCurrentUser()) + .fold((l) => null, (r) => r); if (getCurrentUser == null) { emit(const JoinHomeByIdState.error()); } else { @@ -48,7 +45,7 @@ class JoinHomeByIdBloc extends Bloc { id: AllHomesOfUserUniqueId.fromUniqueString(event.id), name: AllHomesOfUserName('home'), ); - final initialization = await _iUserRepository.addHome( + final initialization = await IUserRepository.instance.addHome( getCurrentUser, allHomesOfUserEntity, ); diff --git a/lib/application/light_toggle/light_toggle_bloc.dart b/lib/application/light_toggle/light_toggle_bloc.dart index df867452f..dbd2195c1 100644 --- a/lib/application/light_toggle/light_toggle_bloc.dart +++ b/lib/application/light_toggle/light_toggle_bloc.dart @@ -16,7 +16,7 @@ part 'light_toggle_state.dart'; @injectable class LightToggleBloc extends Bloc { - LightToggleBloc(this._deviceRepository) : super(LightToggleState.initial()) { + LightToggleBloc() : super(LightToggleState.initial()) { on(_initialized); on(_changeState); on(_changeColorTemperature); @@ -24,8 +24,6 @@ class LightToggleBloc extends Bloc { on(_changeBrightness); } - final IDeviceRepository _deviceRepository; - Future _initialized( Initialized event, Emitter emit, @@ -61,11 +59,11 @@ class LightToggleBloc extends Bloc { Either actionResult; if (event.changeToState) { - actionResult = await _deviceRepository.turnOnDevices( + actionResult = await IDeviceRepository.instance.turnOnDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } else { - actionResult = await _deviceRepository.turnOffDevices( + actionResult = await IDeviceRepository.instance.turnOffDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } @@ -76,7 +74,7 @@ class LightToggleBloc extends Bloc { Emitter emit, ) async { emit(state.copyWith(colorTemperature: event.newColorTemperature)); - _deviceRepository.changeColorTemperatureDevices( + IDeviceRepository.instance.changeColorTemperatureDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], colorTemperatureToChange: event.newColorTemperature, ); @@ -87,7 +85,7 @@ class LightToggleBloc extends Bloc { Emitter emit, ) async { emit(state.copyWith(hsvColor: event.newHsvColor)); - _deviceRepository.changeHsvColorDevices( + IDeviceRepository.instance.changeHsvColorDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], hsvColorToChange: event.newHsvColor, ); @@ -99,7 +97,7 @@ class LightToggleBloc extends Bloc { ) async { emit(state.copyWith(brightness: event.brightness)); - _deviceRepository.changeBrightnessDevices( + IDeviceRepository.instance.changeBrightnessDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], brightnessToChange: event.brightness.round(), ); diff --git a/lib/application/lights/lights_actor/lights_actor_bloc.dart b/lib/application/lights/lights_actor/lights_actor_bloc.dart index c5557522a..000c7110e 100644 --- a/lib/application/lights/lights_actor/lights_actor_bloc.dart +++ b/lib/application/lights/lights_actor/lights_actor_bloc.dart @@ -15,7 +15,7 @@ part 'lights_actor_state.dart'; @injectable class LightsActorBloc extends Bloc { - LightsActorBloc(this._deviceRepository) + LightsActorBloc() : super(const LightsActorState.initial()) { on(_initialized); on(_deleted); @@ -23,7 +23,6 @@ class LightsActorBloc extends Bloc { on(_turnOnAllLights); } - final IDeviceRepository _deviceRepository; Future _initialized( Initialized event, @@ -44,7 +43,7 @@ class LightsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices(devicesId: event.lightsIdToTurnOff); + IDeviceRepository.instance.turnOffDevices(devicesId: event.lightsIdToTurnOff); } Future _turnOnAllLights( @@ -56,6 +55,6 @@ class LightsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.lightsIdToTurnOn); + IDeviceRepository.instance.turnOnDevices(devicesId: event.lightsIdToTurnOn); } } diff --git a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart b/lib/application/lights/lights_watcher/lights_watcher_bloc.dart index 25915482f..522e7111f 100644 --- a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart +++ b/lib/application/lights/lights_watcher/lights_watcher_bloc.dart @@ -15,13 +15,12 @@ part 'lights_watcher_state.dart'; @injectable class LightsWatcherBloc extends Bloc { - LightsWatcherBloc(this._deviceRepository) + LightsWatcherBloc() : super(LightsWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -31,7 +30,7 @@ class LightsWatcherBloc extends Bloc { ) async { emit(const LightsWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchLights().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchLights().listen( (eventWatch) => add(LightsWatcherEvent.devicesReceived(eventWatch)), ); } diff --git a/lib/application/manage_access_point/manage_access_point_bloc.dart b/lib/application/manage_access_point/manage_access_point_bloc.dart index f11e925b4..4d5d8e618 100644 --- a/lib/application/manage_access_point/manage_access_point_bloc.dart +++ b/lib/application/manage_access_point/manage_access_point_bloc.dart @@ -17,14 +17,11 @@ part 'manage_access_point_state.dart'; @injectable class ManageAccessPointBloc extends Bloc { - ManageAccessPointBloc(this._manageAccessPointRepository) - : super(ManageAccessPointState.initial()) { + ManageAccessPointBloc() : super(ManageAccessPointState.initial()) { on(_initialized); on(_doesAccessPointOpen); } - final IManageNetworkRepository _manageAccessPointRepository; - ManageWiFiName? wifiName; ManageWiFiPass? wifiPassword; @@ -41,7 +38,7 @@ class ManageAccessPointBloc ); final Either openedAccessPoint = - await _manageAccessPointRepository + await IManageNetworkRepository.instance .openAccessPoint(manageNetworkEntity); emit( @@ -63,7 +60,7 @@ class ManageAccessPointBloc if (Platform.isAndroid) { final Either openedAccessPoint = - await _manageAccessPointRepository.doesAccessPointOpen(); + await IManageNetworkRepository.instance.doesAccessPointOpen(); emit( openedAccessPoint.fold( diff --git a/lib/application/manage_users/manage_users_bloc.dart b/lib/application/manage_users/manage_users_bloc.dart index ac9b72ac2..89baf6f1c 100644 --- a/lib/application/manage_users/manage_users_bloc.dart +++ b/lib/application/manage_users/manage_users_bloc.dart @@ -15,16 +15,13 @@ part 'manage_users_state.dart'; @injectable class ManageUsersBloc extends Bloc { - ManageUsersBloc(this._userRepository) - : super(const ManageUsersState.initial()) { + ManageUsersBloc() : super(const ManageUsersState.initial()) { on(_initialized); on(_userReceived); on(_addByEmail); on(_deleted); } - final IHomeUserRepository _userRepository; - StreamSubscription>>? _userStreamSubscription; @@ -34,7 +31,7 @@ class ManageUsersBloc extends Bloc { ) async { emit(const ManageUsersState.inProgress()); await _userStreamSubscription?.cancel(); - _userStreamSubscription = _userRepository.getAllUsers().listen( + _userStreamSubscription = IHomeUserRepository.instance.getAllUsers().listen( (allUsersEvent) => add(ManageUsersEvent.userReceived(allUsersEvent)), ); } diff --git a/lib/application/manage_wifi/manage_wifi_bloc.dart b/lib/application/manage_wifi/manage_wifi_bloc.dart index 8ca7f9421..8bb3407fa 100644 --- a/lib/application/manage_wifi/manage_wifi_bloc.dart +++ b/lib/application/manage_wifi/manage_wifi_bloc.dart @@ -15,8 +15,7 @@ part 'manage_wifi_state.dart'; @injectable class ManageWifiBloc extends Bloc { - ManageWifiBloc(this._manageWiFiRepository) - : super(ManageWifiState.initial()) { + ManageWifiBloc() : super(ManageWifiState.initial()) { on(_initialized); on(_scanForWiFiNetworks); on(_connectToWiFi); @@ -24,8 +23,6 @@ class ManageWifiBloc extends Bloc { on(_wifiPassChanged); } - final IManageNetworkRepository _manageWiFiRepository; - ManageWiFiName? wifiName; ManageWiFiPass? wifiPassword; @@ -36,7 +33,7 @@ class ManageWifiBloc extends Bloc { emit(ManageWifiState.loading()); final Either doesWiFiEnabled = - await _manageWiFiRepository.doesWiFiEnabled(); + await IManageNetworkRepository.instance.doesWiFiEnabled(); emit( doesWiFiEnabled.fold((f) => ManageWifiState.wifiIsDisabled(), (r) { @@ -66,7 +63,7 @@ class ManageWifiBloc extends Bloc { ); final Either doesWiFiEnabled = - await _manageWiFiRepository.connectToWiFi(manageWiFiEntity); + await IManageNetworkRepository.instance.connectToWiFi(manageWiFiEntity); emit( doesWiFiEnabled.fold( diff --git a/lib/application/more_connections_options/more_connections_options_bloc.dart b/lib/application/more_connections_options/more_connections_options_bloc.dart index cdc38b0c0..2142cf63a 100644 --- a/lib/application/more_connections_options/more_connections_options_bloc.dart +++ b/lib/application/more_connections_options/more_connections_options_bloc.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'package:auto_route/auto_route.dart'; import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; @@ -20,14 +20,12 @@ part 'more_connections_options_state.dart'; @injectable class MoreConnectionsOptionsBloc extends Bloc { - MoreConnectionsOptionsBloc(this._hubConnectionRepository) - : super(MoreConnectionsOptionsState.initial()) { + MoreConnectionsOptionsBloc() : super(MoreConnectionsOptionsState.initial()) { on(_initialEvent); on(_connectToRemotePipes); on(_connectInDemoMode); } - final IHubConnectionRepository _hubConnectionRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -50,7 +48,7 @@ class MoreConnectionsOptionsBloc Emitter emit, ) async { context.router.replace(const HomeRoute()); - _hubConnectionRepository.connectWithHub(demoMod: true); + IHubConnectionRepository.instance.connectWithHub(demoMod: true); } @override diff --git a/lib/application/plus_button_settings/plus_button_settings_bloc.dart b/lib/application/plus_button_settings/plus_button_settings_bloc.dart index 585d0c3f0..da766e996 100644 --- a/lib/application/plus_button_settings/plus_button_settings_bloc.dart +++ b/lib/application/plus_button_settings/plus_button_settings_bloc.dart @@ -14,15 +14,12 @@ part 'plus_button_settings_state.dart'; @injectable class PlusButtonSettingsBloc extends Bloc { - PlusButtonSettingsBloc(this._hubConnectionRepository) - : super(PlusButtonSettingsState.initial()) { + PlusButtonSettingsBloc() : super(PlusButtonSettingsState.initial()) { on(_initialized); on(_logout); } - final IHubConnectionRepository _hubConnectionRepository; - late BuildContext context; Future _initialized( @@ -37,7 +34,8 @@ class PlusButtonSettingsBloc Emitter emit, ) async { emit(PlusButtonSettingsState.loadInProgress()); - await _hubConnectionRepository.closeConnection(); + await IHubConnectionRepository.instance.closeConnection(); + context.router.replace(const ConnectToHubRoute()); } } diff --git a/lib/application/printers/printers_actor/printers_actor_bloc.dart b/lib/application/printers/printers_actor/printers_actor_bloc.dart index 6ed0449e4..520304396 100644 --- a/lib/application/printers/printers_actor/printers_actor_bloc.dart +++ b/lib/application/printers/printers_actor/printers_actor_bloc.dart @@ -18,7 +18,7 @@ part 'printers_actor_state.dart'; @injectable class PrintersActorBloc extends Bloc { - PrintersActorBloc(this._deviceRepository) + PrintersActorBloc() : super(const PrintersActorState.initial()) { on(_initialized); on(_deleted); @@ -28,7 +28,6 @@ class PrintersActorBloc extends Bloc { on(_shutdownAllPrinters); } - final IDeviceRepository _deviceRepository; Future _initialized( Initialized event, @@ -49,7 +48,7 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices( + IDeviceRepository.instance.turnOffDevices( devicesId: event.printersIdToTurnOff, ); } @@ -63,7 +62,7 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.printersIdToTurnOn); + IDeviceRepository.instance.turnOnDevices(devicesId: event.printersIdToTurnOn); } Future _openPrintersWebPage( @@ -100,6 +99,6 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.shutdownDevices(devicesId: event.printersId); + IDeviceRepository.instance.shutdownDevices(devicesId: event.printersId); } } diff --git a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart b/lib/application/printers/printers_watcher/printers_watcher_bloc.dart index f9e96338d..d51daef37 100644 --- a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart +++ b/lib/application/printers/printers_watcher/printers_watcher_bloc.dart @@ -16,13 +16,12 @@ part 'printers_watcher_state.dart'; @injectable class PrintersWatcherBloc extends Bloc { - PrintersWatcherBloc(this._deviceRepository) + PrintersWatcherBloc() : super(PrintersWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -32,7 +31,7 @@ class PrintersWatcherBloc ) async { emit(const PrintersWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchPrinters().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchPrinters().listen( (eventWatch) => add(PrintersWatcherEvent.devicesReceived(eventWatch)), ); } diff --git a/lib/application/remote_pipes/remote_pipes_bloc.dart b/lib/application/remote_pipes/remote_pipes_bloc.dart index 8a1d43561..53876dcf1 100644 --- a/lib/application/remote_pipes/remote_pipes_bloc.dart +++ b/lib/application/remote_pipes/remote_pipes_bloc.dart @@ -14,16 +14,13 @@ part 'remote_pipes_state.dart'; @injectable class RemotePipesBloc extends Bloc { - RemotePipesBloc(this._remotePipesRepository) - : super(RemotePipesState.initial()) { + RemotePipesBloc() : super(RemotePipesState.initial()) { on(_initialized); on(_remotePipesDomainChanged); on(_permissionChanged); on(_addRemotePipeUrl); } - final IRemotePipesRepository _remotePipesRepository; - Future _initialized( Initialized event, Emitter emit, @@ -61,7 +58,7 @@ class RemotePipesBloc extends Bloc { ), ); - final remotePipesSetDomainResponse = await _remotePipesRepository + final remotePipesSetDomainResponse = await IRemotePipesRepository.instance .setRemotePipesDomainName(remotePipesEntity); Navigator.pop(event.context); } diff --git a/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart b/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart index b3be30416..48769d2b3 100644 --- a/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart +++ b/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart @@ -19,7 +19,7 @@ part 'room_sign_in_form_state.dart'; @injectable class RoomSignInFormBloc extends Bloc { - RoomSignInFormBloc(this._deviceRepository) + RoomSignInFormBloc() : super(RoomSignInFormState.initial()) { on(_createRoom); on(_changeRoomDevices); @@ -34,7 +34,6 @@ class RoomSignInFormBloc add(const RoomSignInFormEvent.initialized()); } - final IDeviceRepository _deviceRepository; List _allRooms = []; List _allDevices = []; @@ -47,7 +46,7 @@ class RoomSignInFormBloc _allRooms = List.from(r.iter); }); - (await _deviceRepository.getAllDevices()).fold((l) => null, (r) { + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { _allDevices = List.from(r.iter); }); _allRooms.removeWhere((element) => element == null); diff --git a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart index 8a763f1a8..0d5879c58 100644 --- a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart +++ b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart @@ -16,7 +16,7 @@ part 'smart_computers_actor_state.dart'; @injectable class SmartComputersActorBloc extends Bloc { - SmartComputersActorBloc(this._deviceRepository) + SmartComputersActorBloc() : super(const SmartComputersActorState.initial()) { on(_initialized); on(_deleted); @@ -26,8 +26,6 @@ class SmartComputersActorBloc on(_shutdownAllSmartComputers); } - final IDeviceRepository _deviceRepository; - Future _initialized( Initialized event, Emitter emit, @@ -47,7 +45,7 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices( + IDeviceRepository.instance.turnOffDevices( devicesId: event.smartComputersIdToTurnOff, ); } @@ -61,7 +59,7 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.smartComputersIdToTurnOn); + IDeviceRepository.instance.turnOnDevices(devicesId: event.smartComputersIdToTurnOn); } Future _suspendAllSmartComputers( @@ -73,7 +71,7 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.suspendDevices(devicesId: event.smartComputersId); + IDeviceRepository.instance.suspendDevices(devicesId: event.smartComputersId); } Future _shutdownAllSmartComputers( @@ -85,6 +83,6 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.shutdownDevices(devicesId: event.smartComputersId); + IDeviceRepository.instance.shutdownDevices(devicesId: event.smartComputersId); } } diff --git a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart index 86b73d76c..4d445d23c 100644 --- a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart +++ b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart @@ -16,13 +16,12 @@ part 'smart_computer_watcher_state.dart'; @injectable class SmartComputersWatcherBloc extends Bloc { - SmartComputersWatcherBloc(this._deviceRepository) + SmartComputersWatcherBloc() : super(SmartComputersWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -32,7 +31,7 @@ class SmartComputersWatcherBloc ) async { emit(const SmartComputersWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchSmartComputers().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchSmartComputers().listen( (eventWatch) => add(SmartComputersWatcherEvent.devicesReceived(eventWatch)), ); diff --git a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart b/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart index c83ae5b2e..805ab59e7 100644 --- a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart +++ b/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart @@ -16,14 +16,13 @@ part 'smart_plug_toggle_state.dart'; @injectable class SmartPlugToggleBloc extends Bloc { - SmartPlugToggleBloc(this._deviceRepository) + SmartPlugToggleBloc() : super(SmartPlugToggleState.initial()) { on(_create); on(_changeAction); on(_changeColor); } - final IDeviceRepository _deviceRepository; int sendNewColorEachMiliseconds = 200; Timer? timeFromLastColorChange; @@ -33,7 +32,7 @@ class SmartPlugToggleBloc CreateDevice event, Emitter emit, ) async { - final actionResult = await _deviceRepository.create(event.deviceEntity); + final actionResult = await IDeviceRepository.instance.create(event.deviceEntity); } Future _changeAction( @@ -45,11 +44,11 @@ class SmartPlugToggleBloc Either actionResult; if (event.changeToState) { - actionResult = await _deviceRepository.turnOnDevices( + actionResult = await IDeviceRepository.instance.turnOnDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } else { - actionResult = await _deviceRepository.turnOffDevices( + actionResult = await IDeviceRepository.instance.turnOffDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } @@ -79,7 +78,7 @@ class SmartPlugToggleBloc /// different colors which is not efficient and some device can't even handle /// so many requests. Future changeColorOncePerTimer(ChangeColor e) async { - await _deviceRepository.changeHsvColorDevices( + await IDeviceRepository.instance.changeHsvColorDevices( devicesId: [e.deviceEntity.uniqueId.getOrCrash()], hsvColorToChange: lastColoredPicked!, ); diff --git a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart index b3f3666af..179862530 100644 --- a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart +++ b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart @@ -16,7 +16,7 @@ part 'smart_plugs_actor_state.dart'; @injectable class SmartPlugsActorBloc extends Bloc { - SmartPlugsActorBloc(this._deviceRepository) + SmartPlugsActorBloc() : super(const SmartPlugsActorState.initial()) { on(_initialized); on(_deleted); @@ -24,7 +24,6 @@ class SmartPlugsActorBloc on(_turnOnAllSmartPlugs); } - final IDeviceRepository _deviceRepository; Future _initialized( Initialized event, @@ -45,7 +44,7 @@ class SmartPlugsActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices(devicesId: event.smartPlugsIdToTurnOff); + IDeviceRepository.instance.turnOffDevices(devicesId: event.smartPlugsIdToTurnOff); } Future _turnOnAllSmartPlugs( @@ -57,6 +56,6 @@ class SmartPlugsActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.smartPlugsIdToTurnOn); + IDeviceRepository.instance.turnOnDevices(devicesId: event.smartPlugsIdToTurnOn); } } diff --git a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart index d6eeb4e48..3ffe207bd 100644 --- a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart +++ b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart @@ -16,13 +16,12 @@ part 'smart_plugs_watcher_state.dart'; @injectable class SmartPlugsWatcherBloc extends Bloc { - SmartPlugsWatcherBloc(this._deviceRepository) + SmartPlugsWatcherBloc() : super(SmartPlugsWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -32,7 +31,7 @@ class SmartPlugsWatcherBloc ) async { emit(const SmartPlugsWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchSmartPlugs().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchSmartPlugs().listen( (eventWatch) => add(SmartPlugsWatcherEvent.devicesReceived(eventWatch)), ); diff --git a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart b/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart index 7a6c75d33..e9bf00035 100644 --- a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart +++ b/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart @@ -14,7 +14,7 @@ part 'smart_tv_actor_state.dart'; @injectable class SmartTvActorBloc extends Bloc { - SmartTvActorBloc(this._deviceRepository) + SmartTvActorBloc() : super(const SmartTvActorState.initial()) { on(_initialized); on(_openUrl); @@ -28,8 +28,6 @@ class SmartTvActorBloc extends Bloc { on(_queueNextEvent); } - final IDeviceRepository _deviceRepository; - Future _initialized( Initialized event, Emitter emit, @@ -43,7 +41,7 @@ class SmartTvActorBloc extends Bloc { message: 'Open url on smart tv', linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.openUrlOnDevices( + IDeviceRepository.instance.openUrlOnDevices( devicesId: event.smartTvId, url: event.url, ); @@ -58,7 +56,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.stopStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.stopStateDevices(devicesId: event.smartTvId); } Future _closeEvent( @@ -70,7 +68,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.closeStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.closeStateDevices(devicesId: event.smartTvId); } Future _pauseState( @@ -82,7 +80,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.pauseStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.pauseStateDevices(devicesId: event.smartTvId); } Future _playState( @@ -94,7 +92,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.playStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.playStateDevices(devicesId: event.smartTvId); } Future _skipVideoTo( @@ -106,7 +104,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.skipVideoDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.skipVideoDevices(devicesId: event.smartTvId); } Future _changeVolume( @@ -118,7 +116,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.changeVolumeDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.changeVolumeDevices(devicesId: event.smartTvId); } Future _queuePrevEvent( @@ -130,7 +128,7 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.queuePrevStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.queuePrevStateDevices(devicesId: event.smartTvId); } Future _queueNextEvent( @@ -142,6 +140,6 @@ class SmartTvActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.queueNextStateDevices(devicesId: event.smartTvId); + IDeviceRepository.instance.queueNextStateDevices(devicesId: event.smartTvId); } } diff --git a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart b/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart index 7ef5d6cbb..dbabf0039 100644 --- a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart +++ b/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart @@ -17,7 +17,7 @@ part 'smart_tv_watcher_state.dart'; @injectable class SmartTvWatcherBloc extends Bloc { - SmartTvWatcherBloc(this._deviceRepository) + SmartTvWatcherBloc() : super(SmartTvWatcherState.initial()) { on(_watchAllStarted); on(_smartTvReceived); @@ -29,7 +29,7 @@ class SmartTvWatcherBloc ) async { emit(const SmartTvWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchSmartTv().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchSmartTv().listen( (eventWatch) => add(SmartTvWatcherEvent.smartTvReceived(eventWatch)), ); } @@ -50,7 +50,6 @@ class SmartTvWatcherBloc ); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; diff --git a/lib/application/software_info/software_info_bloc.dart b/lib/application/software_info/software_info_bloc.dart index 045c964f5..0547e1f8a 100644 --- a/lib/application/software_info/software_info_bloc.dart +++ b/lib/application/software_info/software_info_bloc.dart @@ -12,14 +12,11 @@ part 'software_info_state.dart'; @injectable class SoftwareInfoBloc extends Bloc { - SoftwareInfoBloc(this._softwareInfoRepository) - : super(SoftwareInfoState.initial()) { + SoftwareInfoBloc() : super(SoftwareInfoState.initial()) { on(_initialized); on(_getSoftwareInfo); } - final ISoftwareInfoRepository _softwareInfoRepository; - Map softwaresInfo = {}; Future _initialized( @@ -27,7 +24,7 @@ class SoftwareInfoBloc extends Bloc { Emitter emit, ) async { SoftwareInfoEntity? appInfoEntity; - (await _softwareInfoRepository.getAppSoftwareInfo()).fold( + (await ISoftwareInfoRepository.instance.getAppSoftwareInfo()).fold( (l) => l, (r) { appInfoEntity = r; @@ -40,7 +37,7 @@ class SoftwareInfoBloc extends Bloc { } SoftwareInfoEntity? hubInfoEntity; - (await _softwareInfoRepository.getHubSoftwareInfo()).fold( + (await ISoftwareInfoRepository.instance.getHubSoftwareInfo()).fold( (l) => l, (r) { hubInfoEntity = r; @@ -54,7 +51,7 @@ class SoftwareInfoBloc extends Bloc { } SoftwareInfoEntity? securityBearInfoEntity; - (await _softwareInfoRepository.getSecurityBearSoftwareInfo()).fold( + (await ISoftwareInfoRepository.instance.getSecurityBearSoftwareInfo()).fold( (l) => l, (r) { securityBearInfoEntity = r; diff --git a/lib/application/switch_toggle/switch_toggle_bloc.dart b/lib/application/switch_toggle/switch_toggle_bloc.dart index aed6bdfe3..a79a993ce 100644 --- a/lib/application/switch_toggle/switch_toggle_bloc.dart +++ b/lib/application/switch_toggle/switch_toggle_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/widgets.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -15,15 +15,12 @@ part 'switch_toggle_state.dart'; @injectable class SwitchToggleBloc extends Bloc { - SwitchToggleBloc(this._deviceRepository) - : super(SwitchToggleState.initial()) { + SwitchToggleBloc() : super(SwitchToggleState.initial()) { on(_create); on(_changeAction); on(_changeColor); } - final IDeviceRepository _deviceRepository; - int sendNewColorEachMiliseconds = 200; Timer? timeFromLastColorChange; HSVColor? lastColoredPicked; @@ -32,7 +29,8 @@ class SwitchToggleBloc extends Bloc { CreateDevice event, Emitter emit, ) async { - final actionResult = await _deviceRepository.create(event.deviceEntity); + final actionResult = + await IDeviceRepository.instance.create(event.deviceEntity); } Future _changeAction( @@ -44,11 +42,11 @@ class SwitchToggleBloc extends Bloc { Either actionResult; if (event.changeToState) { - actionResult = await _deviceRepository.turnOnDevices( + actionResult = await IDeviceRepository.instance.turnOnDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } else { - actionResult = await _deviceRepository.turnOffDevices( + actionResult = await IDeviceRepository.instance.turnOffDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } @@ -78,7 +76,7 @@ class SwitchToggleBloc extends Bloc { /// different colors which is not efficient and some device can't even handle /// so many requests. Future changeColorOncePerTimer(ChangeColor e) async { - await _deviceRepository.changeHsvColorDevices( + await IDeviceRepository.instance.changeHsvColorDevices( devicesId: [e.deviceEntity.uniqueId.getOrCrash()], hsvColorToChange: lastColoredPicked!, ); diff --git a/lib/application/switches/switches_actor/switches_actor_bloc.dart b/lib/application/switches/switches_actor/switches_actor_bloc.dart index bc30ca6cc..de8b440fe 100644 --- a/lib/application/switches/switches_actor/switches_actor_bloc.dart +++ b/lib/application/switches/switches_actor/switches_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -15,16 +15,13 @@ part 'switches_actor_state.dart'; @injectable class SwitchesActorBloc extends Bloc { - SwitchesActorBloc(this._deviceRepository) - : super(const SwitchesActorState.initial()) { + SwitchesActorBloc() : super(const SwitchesActorState.initial()) { on(_initialized); on(_deleted); on(_turnOffAllSwitches); on(_turnOnAllSwitches); } - final IDeviceRepository _deviceRepository; - Future _initialized( Initialized event, Emitter emit, @@ -44,7 +41,8 @@ class SwitchesActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOffDevices(devicesId: event.switchesIdToTurnOff); + IDeviceRepository.instance + .turnOffDevices(devicesId: event.switchesIdToTurnOff); } Future _turnOnAllSwitches( @@ -56,6 +54,7 @@ class SwitchesActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - _deviceRepository.turnOnDevices(devicesId: event.switchesIdToTurnOn); + IDeviceRepository.instance + .turnOnDevices(devicesId: event.switchesIdToTurnOn); } } diff --git a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart b/lib/application/switches/switches_watcher/switches_watcher_bloc.dart index 4caec275a..95fd3fcc3 100644 --- a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart +++ b/lib/application/switches/switches_watcher/switches_watcher_bloc.dart @@ -16,13 +16,12 @@ part 'switches_watcher_state.dart'; @injectable class SwitchesWatcherBloc extends Bloc { - SwitchesWatcherBloc(this._deviceRepository) + SwitchesWatcherBloc() : super(SwitchesWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } - final IDeviceRepository _deviceRepository; StreamSubscription>>? _deviceStreamSubscription; @@ -32,7 +31,7 @@ class SwitchesWatcherBloc ) async { emit(const SwitchesWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = _deviceRepository.watchSwitches().listen( + _deviceStreamSubscription = IDeviceRepository.instance.watchSwitches().listen( (eventWatch) => add(SwitchesWatcherEvent.devicesReceived(eventWatch)), ); } diff --git a/lib/application/user_homes_list/user_homes_list_bloc.dart b/lib/application/user_homes_list/user_homes_list_bloc.dart index 9b7e512d2..198c66dd7 100644 --- a/lib/application/user_homes_list/user_homes_list_bloc.dart +++ b/lib/application/user_homes_list/user_homes_list_bloc.dart @@ -16,14 +16,12 @@ part 'user_homes_list_state.dart'; @injectable class UserHomesListBloc extends Bloc { - UserHomesListBloc(this._userRepository) - : super(UserHomesListState.initial()) { + UserHomesListBloc() : super(UserHomesListState.initial()) { on(_watchAllStarted); on(_allHomesOfUserReceived); on(_joinExistingHome); } - final IUserRepository _userRepository; StreamSubscription< Either>>? _userHomesStreamSubscription; @@ -34,7 +32,7 @@ class UserHomesListBloc extends Bloc { ) async { emit(const UserHomesListState.loadInProgress()); await _userHomesStreamSubscription?.cancel(); - _userHomesStreamSubscription = _userRepository.watchAll().listen( + _userHomesStreamSubscription = IUserRepository.instance.watchAll().listen( (failureOrDevices) => add( UserHomesListEvent.allHomesOfUserReceived(failureOrDevices), ), @@ -61,8 +59,9 @@ class UserHomesListBloc extends Bloc { ) async { emit(const UserHomesListState.loadInProgress()); - final Either joinHomeOutput = - await _userRepository.joinExistingHome(event.allHomesOfUserEntity!); + final Either joinHomeOutput = await IUserRepository + .instance + .joinExistingHome(event.allHomesOfUserEntity!); emit( joinHomeOutput.fold( (f) => UserHomesListState.loadFailureEnteringHome(f), diff --git a/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart b/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart index 8ce084823..e0525a4f6 100644 --- a/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart +++ b/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart @@ -1,13 +1,14 @@ import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart'; import 'package:dartz/dartz.dart'; -abstract class IAddUserToHomeRepository { - // watch devices - // watch only a - // CUD +abstract interface class IAddUserToHomeRepository { + static IAddUserToHomeRepository? _instance; - // C Read UD + static IAddUserToHomeRepository get instance { + return _instance ??= AddUserToHomeRepository(); + } Future> add( HomeUserEntity homeUserEntity, diff --git a/lib/domain/auth/i_auth_facade.dart b/lib/domain/auth/i_auth_facade.dart index 23a222a5b..25a8823b4 100644 --- a/lib/domain/auth/i_auth_facade.dart +++ b/lib/domain/auth/i_auth_facade.dart @@ -1,6 +1,7 @@ import 'package:cybear_jinni/domain/auth/auth_failure.dart'; import 'package:cybear_jinni/domain/auth/user.dart'; import 'package:cybear_jinni/domain/auth/value_objects.dart'; +import 'package:cybear_jinni/infrastructure/hub_auth_facade/hub_auth_facade.dart'; import 'package:dartz/dartz.dart'; // Class that starts with I is interface. @@ -11,7 +12,13 @@ import 'package:dartz/dartz.dart'; // FirebaseAuth, GoogleSignIn -abstract class IAuthFacade { +abstract interface class IAuthFacade { + static IAuthFacade? _instance; + + static IAuthFacade get instance { + return _instance ??= HubAuthFacade(); + } + Future> getSignedInUser(); Future> getCurrentHome(); diff --git a/lib/domain/cbj_comp/i_cbj_comp_repository.dart b/lib/domain/cbj_comp/i_cbj_comp_repository.dart index 8f4f2dda0..3721a8cb0 100644 --- a/lib/domain/cbj_comp/i_cbj_comp_repository.dart +++ b/lib/domain/cbj_comp/i_cbj_comp_repository.dart @@ -1,13 +1,14 @@ import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; +import 'package:cybear_jinni/infrastructure/cbj_comp/cbj_comp_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class ICBJCompRepository { - // watch devices - // watch only a - // CUD +abstract interface class ICBJCompRepository { + static ICBJCompRepository? _instance; - // C Read UD + static ICBJCompRepository get instance { + return _instance ??= CBJCompRepository(); + } Future> shutdownServer(); diff --git a/lib/domain/create_home/i_create_home_repository.dart b/lib/domain/create_home/i_create_home_repository.dart index 061f48b79..2b83f7c9c 100644 --- a/lib/domain/create_home/i_create_home_repository.dart +++ b/lib/domain/create_home/i_create_home_repository.dart @@ -2,9 +2,16 @@ import 'package:cybear_jinni/domain/create_home/create_home_entity.dart'; import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; +import 'package:cybear_jinni/infrastructure/create_home/create_home_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class ICreateHomeRepository { +abstract interface class ICreateHomeRepository { + static ICreateHomeRepository? _instance; + + static ICreateHomeRepository get instance { + return _instance ??= CreateHomeRepository(); + } + Future> createNewHome( CreateHomeEntity createHomeEntity, ); diff --git a/lib/domain/device/i_device_repository.dart b/lib/domain/device/i_device_repository.dart index 23b8585a3..ddb9e6ed6 100644 --- a/lib/domain/device/i_device_repository.dart +++ b/lib/domain/device/i_device_repository.dart @@ -3,12 +3,19 @@ import 'dart:async'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/infrastructure/devices/device/device_repository.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/widgets.dart'; import 'package:kt_dart/kt.dart'; import 'package:rxdart/rxdart.dart'; -abstract class IDeviceRepository { +abstract interface class IDeviceRepository { + static IDeviceRepository? _instance; + + static IDeviceRepository get instance { + return _instance ??= DeviceRepository(); + } + void addOrUpdateDevice(DeviceEntityAbstract deviceEntity); void addOrUpdateDeviceAndStateToWaiting(DeviceEntityAbstract deviceEntity); diff --git a/lib/domain/home_user/i_home_user_repository.dart b/lib/domain/home_user/i_home_user_repository.dart index 791aaa690..cabd775c5 100644 --- a/lib/domain/home_user/i_home_user_repository.dart +++ b/lib/domain/home_user/i_home_user_repository.dart @@ -1,14 +1,15 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; +import 'package:cybear_jinni/infrastructure/home_user/home_user_repository.dart'; import 'package:dartz/dartz.dart'; import 'package:kt_dart/collection.dart'; -abstract class IHomeUserRepository { - // watch devices - // watch only a - // CUD +abstract interface class IHomeUserRepository { + static IHomeUserRepository? _instance; - // C Read UD + static IHomeUserRepository get instance { + return _instance ??= HomeUserRepository(); + } Stream>> getAllUsers(); diff --git a/lib/domain/hub/i_hub_connection_repository.dart b/lib/domain/hub/i_hub_connection_repository.dart index 5900f9cf3..d2313dd07 100644 --- a/lib/domain/hub/i_hub_connection_repository.dart +++ b/lib/domain/hub/i_hub_connection_repository.dart @@ -1,9 +1,16 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/domain/hub/hub_entity.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; +import 'package:cybear_jinni/infrastructure/hub_client/hub_connection_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class IHubConnectionRepository { +abstract interface class IHubConnectionRepository { + static IHubConnectionRepository? _instance; + + static IHubConnectionRepository get instance { + return _instance ??= HubConnectionRepository(); + } + static HubEntity? hubEntity; Future connectWithHub({bool demoMod = false}); diff --git a/lib/domain/local_db/i_local_db_repository2.dart b/lib/domain/local_db/i_local_db_repository2.dart index 7846572ca..ca1a3f5bd 100644 --- a/lib/domain/local_db/i_local_db_repository2.dart +++ b/lib/domain/local_db/i_local_db_repository2.dart @@ -1,9 +1,16 @@ import 'package:cbj_integrations_controller/domain/local_db/local_db_failures.dart'; +import 'package:cybear_jinni/infrastructure/isar_local_db/isar_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class ILocalDbRepository2 { - String remotePipesBoxName = 'remotePipesBox'; - String hubEntityBoxName = 'hubEntityBox'; +abstract interface class ILocalDbRepository2 { + static ILocalDbRepository2? _instance; + + static ILocalDbRepository2 get instance { + return _instance ??= IsarRepository(); + } + + static String remotePipesBoxName = 'remotePipesBox'; + static String hubEntityBoxName = 'hubEntityBox'; Future setHomeId(String homeId); diff --git a/lib/domain/manage_network/i_manage_network_repository.dart b/lib/domain/manage_network/i_manage_network_repository.dart index b4420c526..d6a902c51 100644 --- a/lib/domain/manage_network/i_manage_network_repository.dart +++ b/lib/domain/manage_network/i_manage_network_repository.dart @@ -1,14 +1,16 @@ import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/infrastructure/manage_wifi/manage_wifi_repository.dart'; import 'package:dartz/dartz.dart'; import 'package:kt_dart/collection.dart'; -abstract class IManageNetworkRepository { - // watch devices - // watch only a - // CUD +abstract interface class IManageNetworkRepository { + static IManageNetworkRepository? _instance; + + static IManageNetworkRepository get instance { + return _instance ??= ManageWiFiRepository(); + } - // C Read UD static ManageNetworkEntity? manageWiFiEntity; Future> doesWiFiEnabled(); diff --git a/lib/domain/remote_pipes/i_remote_pipes_repository.dart b/lib/domain/remote_pipes/i_remote_pipes_repository.dart index 1345b0a4d..27fa0bf70 100644 --- a/lib/domain/remote_pipes/i_remote_pipes_repository.dart +++ b/lib/domain/remote_pipes/i_remote_pipes_repository.dart @@ -1,8 +1,15 @@ import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; +import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class IRemotePipesRepository { +abstract interface class IRemotePipesRepository { + static IRemotePipesRepository? _instance; + + static IRemotePipesRepository get instance { + return _instance ??= RemotePipesRepository(); + } + Future> setRemotePipesDomainName( RemotePipesEntity remotePipesEntity, ); diff --git a/lib/domain/security_bear/i_security_bear_connection_repository.dart b/lib/domain/security_bear/i_security_bear_connection_repository.dart index 14cb3c738..c8496fec1 100644 --- a/lib/domain/security_bear/i_security_bear_connection_repository.dart +++ b/lib/domain/security_bear/i_security_bear_connection_repository.dart @@ -1,9 +1,16 @@ import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; import 'package:cybear_jinni/infrastructure/core/gen/security_bear/client/protoc_as_dart/security_bear_connections.pbgrpc.dart'; +import 'package:cybear_jinni/infrastructure/security_bear_client/security_bear_connection_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class ISecurityBearConnectionRepository { +abstract interface class ISecurityBearConnectionRepository { + static ISecurityBearConnectionRepository? _instance; + + static ISecurityBearConnectionRepository get instance { + return _instance ??= SecurityBearConnectionRepository(); + } + Future> getSecurityBearCompInfo( CompSecurityBearInfo appInfoForSecurityBear, diff --git a/lib/domain/software_info/i_software_info_repository.dart b/lib/domain/software_info/i_software_info_repository.dart index 18386304e..644050a91 100644 --- a/lib/domain/software_info/i_software_info_repository.dart +++ b/lib/domain/software_info/i_software_info_repository.dart @@ -1,8 +1,15 @@ import 'package:cybear_jinni/domain/software_info/software_info_entity.dart'; import 'package:cybear_jinni/domain/software_info/software_info_failures.dart'; +import 'package:cybear_jinni/infrastructure/software_info/software_info_repository.dart'; import 'package:dartz/dartz.dart'; -abstract class ISoftwareInfoRepository { +abstract interface class ISoftwareInfoRepository { + static ISoftwareInfoRepository? _instance; + + static ISoftwareInfoRepository get instance { + return _instance ??= SoftwareInfoRepository(); + } + Future> getAppSoftwareInfo(); Future> getHubSoftwareInfo(); diff --git a/lib/domain/user/all_homes_of_user/i_all_homes_of_user_repository.dart b/lib/domain/user/all_homes_of_user/i_all_homes_of_user_repository.dart index 03ca51c12..fc2bcec8b 100644 --- a/lib/domain/user/all_homes_of_user/i_all_homes_of_user_repository.dart +++ b/lib/domain/user/all_homes_of_user/i_all_homes_of_user_repository.dart @@ -2,7 +2,7 @@ import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_fai import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:dartz/dartz.dart'; -abstract class IAllHomesOfUserRepository { +abstract interface class IAllHomesOfUserRepository { // watch devices // watch only a // CUD diff --git a/lib/domain/user/i_user_repository.dart b/lib/domain/user/i_user_repository.dart index c6b8d2d69..9430fb2ba 100644 --- a/lib/domain/user/i_user_repository.dart +++ b/lib/domain/user/i_user_repository.dart @@ -2,15 +2,16 @@ import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_failures.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; +import 'package:cybear_jinni/infrastructure/user/user_repository.dart'; import 'package:dartz/dartz.dart'; import 'package:kt_dart/kt.dart'; -abstract class IUserRepository { - // watch devices - // watch only a - // CUD +abstract interface class IUserRepository { + static IUserRepository? _instance; - // C Read UD + static IUserRepository get instance { + return _instance ??= UserRepository(); + } Future> create(UserEntity deviceEntity); diff --git a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart b/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart index f203e29bc..2a51bd3ab 100644 --- a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart +++ b/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart @@ -8,13 +8,9 @@ import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:injectable/injectable.dart'; -@LazySingleton(as: IAddUserToHomeRepository) class AddUserToHomeRepository implements IAddUserToHomeRepository { - AddUserToHomeRepository(this._firestore); - - final String _firestore; + AddUserToHomeRepository(); @override @required @@ -87,7 +83,7 @@ class AddUserToHomeRepository implements IAddUserToHomeRepository { // ); // await create(homeUserEntityToAdd); - final String homeId = await getIt().getHomeId(); + final String homeId = await ILocalDbRepository2.instance.getHomeId(); return Right(homeId); } catch (e) { return const Left(AddUserToHomeFailures.unexpected()); diff --git a/lib/infrastructure/cbj_comp/cbj_comp_repository.dart b/lib/infrastructure/cbj_comp/cbj_comp_repository.dart index f9ea81aac..b25cd01e0 100644 --- a/lib/infrastructure/cbj_comp/cbj_comp_repository.dart +++ b/lib/infrastructure/cbj_comp/cbj_comp_repository.dart @@ -6,9 +6,7 @@ import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; import 'package:cybear_jinni/infrastructure/cbj_app_server/cbj_app_server_d.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; -@LazySingleton(as: ICBJCompRepository) class CBJCompRepository implements ICBJCompRepository { @override Future> shutdownServer() async { @@ -24,14 +22,14 @@ class CBJCompRepository implements ICBJCompRepository { // final CompHubInfo compInfo = await compEntityToCompInfo(cBJCompEntity); // // final UserEntity deviceUser = - // (await getIt().getDeviceUserFromHome()) + // (await ICreateHomeRepository.instance.getDeviceUserFromHome()) // .getOrElse(() => throw "Device user can't be found"); // // final String fireBaseProjectId = ConstantCredentials.fireBaseProjectId; // final String fireBaseApiKey = ConstantCredentials.fireBaseApiKey; // final String userEmail = deviceUser.email!.getOrCrash(); // final String userPassword = deviceUser.pass!.getOrCrash(); - // final String homeId = (await getIt().getCurrentHome()) + // final String homeId = (await IAuthFacade.instance.getCurrentHome()) // .getOrElse(() => throw MissingCurrentHomeError()) // .id // .getOrCrash()!; diff --git a/lib/infrastructure/create_home/create_home_repository.dart b/lib/infrastructure/create_home/create_home_repository.dart index 7cb5acb51..fdf79b334 100644 --- a/lib/infrastructure/create_home/create_home_repository.dart +++ b/lib/infrastructure/create_home/create_home_repository.dart @@ -22,9 +22,7 @@ import 'package:cybear_jinni/infrastructure/create_home/create_home_dtos.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; -import 'package:injectable/injectable.dart'; -@LazySingleton(as: ICreateHomeRepository) class CreateHomeRepository implements ICreateHomeRepository { final String smartHomesPath = 'SmartHomes'; final String usersInHomePath = 'Users'; @@ -42,13 +40,13 @@ class CreateHomeRepository implements ICreateHomeRepository { createHomeEntity.copyWith(id: HomeUniqueId()); final UserEntity userEntity = - (await getIt().getCurrentUser()).getOrElse( + (await IUserRepository.instance.getCurrentUser()).getOrElse( () => throw UserUnexpectedValueError(const UserFailures.unexpected()), ); // Create user for devices final registerDeviceUser = - await getIt().registerWithEmailAndPasswordReturnUserId( + await IAuthFacade.instance.registerWithEmailAndPasswordReturnUserId( emailAddress: EmailAddress( createHomeEntityWithId.homeDevicesUserEmail!.getOrCrash(), ), @@ -66,7 +64,7 @@ class CreateHomeRepository implements ICreateHomeRepository { ); // create home with the current user - await getIt() + await ILocalDbRepository2.instance .setHomeId(createHomeEntityWithId.id.getOrCrash()); final creatingHomeWithUser = await addUserToHome(userEntity); @@ -116,7 +114,7 @@ class CreateHomeRepository implements ICreateHomeRepository { id: AllHomesOfUserUniqueId.fromUniqueString(homeId), name: AllHomesOfUserName(homeName), ); - final addHomeToUserHomesList = await getIt() + final addHomeToUserHomesList = await IUserRepository.instance .addHome(userEntity, allHomesOfUserEntity); addHomeToUserHomesList.getOrElse( @@ -227,7 +225,7 @@ class CreateHomeRepository implements ICreateHomeRepository { ); final Either createHome = - await getIt().create(homeUserEntity); + await IAddUserToHomeRepository.instance.create(homeUserEntity); createHome.getOrElse( () => throw UserUnexpectedValueError(const UserFailures.unexpected()), ); diff --git a/lib/infrastructure/devices/device/device_repository.dart b/lib/infrastructure/devices/device/device_repository.dart index 8b8df6c47..01b755d5a 100644 --- a/lib/infrastructure/devices/device/device_repository.dart +++ b/lib/infrastructure/devices/device/device_repository.dart @@ -37,14 +37,12 @@ import 'package:dartz/dartz.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/services.dart'; import 'package:flutter/src/painting/colors.dart'; -import 'package:injectable/injectable.dart'; import 'package:kt_dart/kt.dart'; import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:rxdart/rxdart.dart'; -@LazySingleton(as: IDeviceRepository) class DeviceRepository implements IDeviceRepository { // final DeviceRemoteService _deviceRemoteService; // final DeviceLocalService _deviceLocalService; @@ -278,7 +276,7 @@ class DeviceRepository implements IDeviceRepository { } final UserEntity currentUserEntity = - (await getIt().getCurrentUser()) + (await IUserRepository.instance.getCurrentUser()) .getOrElse(() => throw 'Cant get current user'); final String currentUserId = currentUserEntity.id!.getOrCrash()!; diff --git a/lib/infrastructure/home_user/home_user_repository.dart b/lib/infrastructure/home_user/home_user_repository.dart index 7cfdca8d0..22f558d1f 100644 --- a/lib/infrastructure/home_user/home_user_repository.dart +++ b/lib/infrastructure/home_user/home_user_repository.dart @@ -2,10 +2,8 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; import 'package:cybear_jinni/domain/home_user/i_home_user_repository.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; import 'package:kt_dart/collection.dart'; -@LazySingleton(as: IHomeUserRepository) class HomeUserRepository implements IHomeUserRepository { @override Future> add( diff --git a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart b/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart index d5874b33f..5af91d637 100644 --- a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart +++ b/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart @@ -10,9 +10,7 @@ import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/domain/user/user_value_objects.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; -@LazySingleton(as: IAuthFacade) class HubAuthFacade implements IAuthFacade { @override Future> getSignedInUser() async => @@ -22,7 +20,7 @@ class HubAuthFacade implements IAuthFacade { Future> getCurrentHome() async => optionOf( MHome( id: UniqueId.fromUniqueString( - await getIt().getHomeId(), + await ILocalDbRepository2.instance.getHomeId(), ), ), ); @@ -71,7 +69,7 @@ class HubAuthFacade implements IAuthFacade { lastName: UserLastName(' '), ); - final registrarOutput = await getIt().create(userEntity); + final registrarOutput = await IUserRepository.instance.create(userEntity); registrarOutput.getOrElse(() => throw NotAuthenticatedError()); final MUser mUser = MUser(id: UniqueId.fromUniqueString(userIdString)); diff --git a/lib/infrastructure/hub_client/hub_connection_repository.dart b/lib/infrastructure/hub_client/hub_connection_repository.dart index 970a900c8..bba8c4114 100644 --- a/lib/infrastructure/hub_client/hub_connection_repository.dart +++ b/lib/infrastructure/hub_client/hub_connection_repository.dart @@ -18,7 +18,6 @@ import 'package:cybear_jinni/infrastructure/hub_client/hub_dtos.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart' show kIsWeb; -import 'package:injectable/injectable.dart'; import 'package:location/location.dart'; import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_info_plus/network_info_plus.dart'; @@ -27,8 +26,7 @@ import 'package:permission_handler/permission_handler.dart' as permission_handler; import 'package:wifi_iot/wifi_iot.dart'; -@LazySingleton(as: IHubConnectionRepository) -class HubConnectionRepository extends IHubConnectionRepository { +class HubConnectionRepository implements IHubConnectionRepository { HubConnectionRepository() { if (currentEnvApp == EnvApp.prod) { hubPort = 50055; @@ -129,19 +127,19 @@ class HubConnectionRepository extends IHubConnectionRepository { if (IHubConnectionRepository.hubEntity == null) { try { String? hubNetworkBssid; - (await getIt().getHubEntityNetworkBssid()).fold( + (await ILocalDbRepository2.instance.getHubEntityNetworkBssid()).fold( (l) => throw 'Error getting Hub network Bssid', (r) => hubNetworkBssid = r, ); String? hubNetworkName; - (await getIt().getHubEntityNetworkName()).fold( + (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( (l) => throw 'Error getting Hub network name', (r) => hubNetworkName = r, ); String? hubNetworkIp; - (await getIt().getHubEntityLastKnownIp()).fold( + (await ILocalDbRepository2.instance.getHubEntityLastKnownIp()).fold( (l) => throw 'Error getting Hub network IP', (r) => hubNetworkIp = r, ); @@ -438,7 +436,7 @@ class HubConnectionRepository extends IHubConnectionRepository { final HubDtos hubDtos = IHubConnectionRepository.hubEntity!.toInfrastructure(); - (await getIt().saveHubEntity( + (await ILocalDbRepository2.instance.saveHubEntity( hubNetworkBssid: hubDtos.hubNetworkBssid, networkName: hubDtos.networkName, lastKnownIp: hubDtos.lastKnownIp, @@ -459,19 +457,19 @@ class HubConnectionRepository extends IHubConnectionRepository { Future loadNetworkInformationFromDb() async { try { String? hubNetworkBssid; - (await getIt().getHubEntityNetworkBssid()).fold( + (await ILocalDbRepository2.instance.getHubEntityNetworkBssid()).fold( (l) => throw 'Error getting Hub network Bssid', (r) => hubNetworkBssid = r, ); String? hubNetworkName; - (await getIt().getHubEntityNetworkName()).fold( + (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( (l) => throw 'Error getting Hub network name', (r) => hubNetworkName = r, ); String? hubNetworkIp; - (await getIt().getHubEntityLastKnownIp()).fold( + (await ILocalDbRepository2.instance.getHubEntityLastKnownIp()).fold( (l) => throw 'Error getting Hub network IP', (r) => hubNetworkIp = r, ); diff --git a/lib/infrastructure/hub_client/hub_requests_routing.dart b/lib/infrastructure/hub_client/hub_requests_routing.dart index 1a35f1af0..fd03a85bd 100644 --- a/lib/infrastructure/hub_client/hub_requests_routing.dart +++ b/lib/infrastructure/hub_client/hub_requests_routing.dart @@ -101,7 +101,7 @@ class HubRequestRouting { navigateRequest(); }); - await getIt().connectWithHub(); + await IHubConnectionRepository.instance.connectWithHub(); } static Future navigateRoomRequest( @@ -218,8 +218,7 @@ class HubRequestRouting { } break; } - - getIt().addOrUpdateDevice(deviceEntity); + IDeviceRepository.instance.addOrUpdateDevice(deviceEntity); } static Future navigateSceneRequest( diff --git a/lib/infrastructure/isar_local_db/isar_repository.dart b/lib/infrastructure/isar_local_db/isar_repository.dart index cabea9520..217833996 100644 --- a/lib/infrastructure/isar_local_db/isar_repository.dart +++ b/lib/infrastructure/isar_local_db/isar_repository.dart @@ -5,12 +5,10 @@ import 'package:cybear_jinni/infrastructure/isar_local_db/isar_objects/hub_entit import 'package:cybear_jinni/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; import 'package:isar/isar.dart'; import 'package:path_provider/path_provider.dart'; -@LazySingleton(as: ILocalDbRepository2) -class IsarRepository extends ILocalDbRepository2 { +class IsarRepository implements ILocalDbRepository2 { IsarRepository() { asyncConstructor(); } diff --git a/lib/infrastructure/manage_wifi/manage_wifi_repository.dart b/lib/infrastructure/manage_wifi/manage_wifi_repository.dart index 39f59f074..8adf80c1a 100644 --- a/lib/infrastructure/manage_wifi/manage_wifi_repository.dart +++ b/lib/infrastructure/manage_wifi/manage_wifi_repository.dart @@ -4,11 +4,9 @@ import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; import 'package:cybear_jinni/infrastructure/core/shared_methods.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; import 'package:kt_dart/collection.dart'; import 'package:wifi_iot/wifi_iot.dart'; -@LazySingleton(as: IManageNetworkRepository) class ManageWiFiRepository implements IManageNetworkRepository { final NetworkSecurity networkSecurity = NetworkSecurity.WPA; diff --git a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart b/lib/infrastructure/remote_pipes/remote_pipes_repository.dart index 571fe326c..858e205a9 100644 --- a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart +++ b/lib/infrastructure/remote_pipes/remote_pipes_repository.dart @@ -8,9 +8,7 @@ import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_dtos.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; -@LazySingleton(as: IRemotePipesRepository) class RemotePipesRepository implements IRemotePipesRepository { @override Future> setRemotePipesDomainName( diff --git a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart index 35ca759da..7a800aa8f 100644 --- a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart +++ b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart @@ -15,16 +15,14 @@ import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart'; -import 'package:injectable/injectable.dart'; import 'package:location/location.dart'; import 'package:network_info_plus/network_info_plus.dart'; import 'package:network_tools/network_tools.dart'; import 'package:permission_handler/permission_handler.dart' as permission_handler; -@LazySingleton(as: ISecurityBearConnectionRepository) class SecurityBearConnectionRepository - extends ISecurityBearConnectionRepository { + implements ISecurityBearConnectionRepository { SecurityBearConnectionRepository() { if (currentEnvApp == EnvApp.dev) { securityBearPort = 60052; @@ -275,7 +273,7 @@ class SecurityBearConnectionRepository ) async { try { final ManageNetworkEntity firstWifiEntityOrFailure = - (await getIt().getFirstWifi()) + (await ICreateHomeRepository.instance.getFirstWifi()) .getOrElse(() => throw 'Error'); final ManageNetworkEntity secondWifiEntityOrFailure = diff --git a/lib/infrastructure/software_info/software_info_repository.dart b/lib/infrastructure/software_info/software_info_repository.dart index 81ddc08b5..844f47719 100644 --- a/lib/infrastructure/software_info/software_info_repository.dart +++ b/lib/infrastructure/software_info/software_info_repository.dart @@ -13,14 +13,11 @@ import 'package:cybear_jinni/domain/software_info/software_info_entity.dart'; import 'package:cybear_jinni/domain/software_info/software_info_failures.dart'; import 'package:cybear_jinni/infrastructure/core/gen/security_bear/client/protoc_as_dart/security_bear_connections.pbgrpc.dart'; import 'package:cybear_jinni/infrastructure/core/gen/security_bear/proto_gen_date.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; import 'package:network_info_plus/network_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart'; -@LazySingleton(as: ISoftwareInfoRepository) class SoftwareInfoRepository implements ISoftwareInfoRepository { @override Future> @@ -66,7 +63,7 @@ class SoftwareInfoRepository implements ISoftwareInfoRepository { appInfoForHub ??= CompHubInfo(); final Either hubResponse = - await getIt().getHubCompInfo(appInfoForHub); + await IHubConnectionRepository.instance.getHubCompInfo(appInfoForHub); return hubResponse.fold( (l) => left(const SoftwareInfoFailures.unexpected()), @@ -90,8 +87,8 @@ class SoftwareInfoRepository implements ISoftwareInfoRepository { appInfoForSecurityBear ??= CompSecurityBearInfo(); final Either - securityBearResponse = - await getIt() + securityBearResponse = await ISecurityBearConnectionRepository + .instance .getSecurityBearCompInfo(appInfoForSecurityBear); return securityBearResponse.fold( diff --git a/lib/infrastructure/user/user_repository.dart b/lib/infrastructure/user/user_repository.dart index db738b8ad..dd7516c0e 100644 --- a/lib/infrastructure/user/user_repository.dart +++ b/lib/infrastructure/user/user_repository.dart @@ -11,10 +11,8 @@ import 'package:cybear_jinni/infrastructure/user/user_dtos.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; -import 'package:injectable/injectable.dart'; import 'package:kt_dart/kt.dart'; -@LazySingleton(as: IUserRepository) class UserRepository implements IUserRepository { @override Future> create(UserEntity userEntity) async { @@ -40,7 +38,7 @@ class UserRepository implements IUserRepository { try { // final userCollec = await _firestore.usersCollection(); - final String userId = (await getIt().getSignedInUser()) + final String userId = (await IAuthFacade.instance.getSignedInUser()) .getOrElse(() => throw NotAuthenticatedError()) .id .getOrCrash(); @@ -95,7 +93,7 @@ class UserRepository implements IUserRepository { // .doc(homeId) // .set(homeUserDtos.toJson()); // - await getIt().setHomeId(homeId); + await ILocalDbRepository2.instance.setHomeId(homeId); return right(unit); } catch (e) { @@ -145,7 +143,7 @@ class UserRepository implements IUserRepository { try { // final homeCollection = await _firestore.homeCollection(); - final String userId = (await getIt().getSignedInUser()) + final String userId = (await IAuthFacade.instance.getSignedInUser()) .getOrElse(() => throw NotAuthenticatedError()) .id .getOrCrash(); @@ -159,7 +157,7 @@ class UserRepository implements IUserRepository { // return left(const HomeUserFailures.homeDoesNotExist()); // } - await getIt().setHomeId(homeId); + await ILocalDbRepository2.instance.setHomeId(homeId); return right(unit); } catch (e) { diff --git a/lib/main.dart b/lib/main.dart index c541c3f94..8f410d3b3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -53,7 +53,7 @@ Future main() async { final appDocDirectory = await getApplicationDocumentsDirectory(); await configureNetworkTools(appDocDirectory.path, enableDebugging: true); HiveRepository(); - getIt(); + ILocalDbRepository2.instance; getIt.registerSingleton(AppRouter()); AdState? adState; diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index 83f406211..db575c926 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -1,6 +1,5 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/home_page/bottom_navigation_bar_home_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/left_navigation_drawer_home_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart'; @@ -20,7 +19,7 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { @override void initState() { - getIt().initiateHubConnection(); + IDeviceRepository.instance.initiateHubConnection(); super.initState(); } diff --git a/pubspec.yaml b/pubspec.yaml index 4f15fb484..a6b68516d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -45,6 +45,8 @@ dependencies: auto_size_text: ^3.0.0 # Helps implement the BLoC pattern. bloc: ^8.1.2 + cbj_integrations_controller: + git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git cbj_smart_device_flutter: git: https://github.com/CyBear-Jinni/cbj_smart_device_flutter.git # Copy text from and to clipboard From dc6cf5ac6c19829665f492f00560b706c35b8014 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 25 Nov 2023 09:59:50 +0200 Subject: [PATCH 02/15] Added the rest of smart device type to the search wip --- .../hub_in_network/hub_in_network_bloc.dart | 19 +-- .../hub/i_hub_connection_repository.dart | 2 - .../commands/flutter_commands.dart | 84 +++++++++++++ .../hub_client/hub_connection_repository.dart | 82 ------------- lib/infrastructure/mqtt/mqtt.dart | 110 ++++++++++++++++++ lib/infrastructure/phone_hub/phone_hub.dart | 98 ++++++++++++++++ lib/main.dart | 12 ++ 7 files changed, 315 insertions(+), 92 deletions(-) create mode 100644 lib/infrastructure/commands/flutter_commands.dart create mode 100644 lib/infrastructure/mqtt/mqtt.dart create mode 100644 lib/infrastructure/phone_hub/phone_hub.dart diff --git a/lib/application/hub_in_network/hub_in_network_bloc.dart b/lib/application/hub_in_network/hub_in_network_bloc.dart index 690c98f3f..ee303aee0 100644 --- a/lib/application/hub_in_network/hub_in_network_bloc.dart +++ b/lib/application/hub_in_network/hub_in_network_bloc.dart @@ -3,9 +3,11 @@ import 'dart:async'; import 'package:auto_route/auto_route.dart'; import 'package:bloc/bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cbj_integrations_controller/utils.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; +import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; @@ -51,10 +53,15 @@ class HubInNetworkBloc extends Bloc { emit( await (await IHubConnectionRepository.instance.searchForHub()).fold( (l) async { - return (await _searchSmartDevices()).fold( - (HubFailures l) => HubInNetworkState.loadFailure(l), - (r) => HubInNetworkState.loadSuccessSecurityCamera(r), - ); + final PhoneHub phoneHub = PhoneHub(); + + final Map smartDevices = + await phoneHub.requestsAndStatusFromHub; + if (smartDevices.isEmpty) { + return HubInNetworkState.loadFailure(l); + } + logger.i('All Devices smartDevices $smartDevices'); + return const HubInNetworkState.loadSuccessSecurityCamera(''); }, (r) { context?.router.replace(const HomeRoute()); return const HubInNetworkState.loadSuccess(); @@ -63,10 +70,6 @@ class HubInNetworkBloc extends Bloc { loading = false; } - Future> _searchSmartDevices() { - return IHubConnectionRepository.instance.containsSmartDevice(); - } - Future _searchHubUsingAnyIpOnTheNetwork( SearchHubUsingAnyIpOnTheNetwork event, Emitter emit, diff --git a/lib/domain/hub/i_hub_connection_repository.dart b/lib/domain/hub/i_hub_connection_repository.dart index d2313dd07..c2526e3c3 100644 --- a/lib/domain/hub/i_hub_connection_repository.dart +++ b/lib/domain/hub/i_hub_connection_repository.dart @@ -26,7 +26,5 @@ abstract interface class IHubConnectionRepository { bool? isThatTheIpOfTheHub, }); - Future> containsSmartDevice(); - Future saveHubIP(String hubIP); } diff --git a/lib/infrastructure/commands/flutter_commands.dart b/lib/infrastructure/commands/flutter_commands.dart new file mode 100644 index 000000000..2353e0ae0 --- /dev/null +++ b/lib/infrastructure/commands/flutter_commands.dart @@ -0,0 +1,84 @@ +import 'dart:io'; + +import 'package:cbj_integrations_controller/infrastructure/system_commands/phone_commands_d/common_batch_commands_d.dart'; +import 'package:path_provider/path_provider.dart'; + +class PhoneCommandsD implements IPhoneCommandsD { + PhoneCommandsD() { + IPhoneCommandsD.instance = this; + } + + String? currentUserName; + String? currentDriveLetter; + + @override + Future getCurrentUserName() async { + return 'cbj_app'; + } + + @override + Future getUuidOfCurrentDevice() async { + return '000000000'; + } + + @override + Future getDeviceHostName() async { + return ''; + } + + @override + Future getAllEtcReleaseFilesText() { + //TODO: add implementation, for now will return getDeviceHostName + return getDeviceHostName(); + } + + @override + Future getFileContent(String fileFullPath) async { + throw UnimplementedError(); + } + + @override + Future getDeviceConfiguration() async { + return ''; + } + + Future getCurrentDriveLetter() async { + return ''; + } + + //TODO: Currently does not work as echo %~dp0 will not work at the command + // line, only in a batch file. + Future getOsDriveLetter() async { + return ''; + } + + @override + Future getLocalDbPath( + Future currentUserName, + ) async { + return (await getApplicationDocumentsDirectory()).path; + } + + @override + Future getProjectFilesLocation() async { + return Directory.current.path; + } + + @override + Future getIpFromMdnsName(String mdnsName) async { + // TODO: implement getIpFromMdnsName + throw UnimplementedError(); + } + + @override + Future suspendComputer() { + // TODO: implement goToSleep + throw UnimplementedError(); + } + + @override + Future shutdownComputer() { + // TODO: implement shutdownComputer + throw UnimplementedError(); + } +} diff --git a/lib/infrastructure/hub_client/hub_connection_repository.dart b/lib/infrastructure/hub_client/hub_connection_repository.dart index bba8c4114..458945190 100644 --- a/lib/infrastructure/hub_client/hub_connection_repository.dart +++ b/lib/infrastructure/hub_client/hub_connection_repository.dart @@ -5,7 +5,6 @@ import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_r import 'package:cbj_integrations_controller/domain/local_db/local_db_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/utils.dart'; -import 'package:cbj_smart_device/application/usecases/smart_server_u/smart_server_u.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:cybear_jinni/domain/hub/hub_entity.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; @@ -601,85 +600,4 @@ class HubConnectionRepository implements IHubConnectionRepository { } return const Left(HubFailures.unexpected()); } - - @override - Future> containsSmartDevice() async { - String? currentDeviceIP; - try { - final NetworkInfo networkInfo = NetworkInfo(); - currentDeviceIP = await networkInfo.getWifiIP(); - - if (currentDeviceIP == null) { - return left(const HubFailures.cantFindHubInNetwork()); - } - - final String subnet = - currentDeviceIP.substring(0, currentDeviceIP.lastIndexOf('.')); - - logger.i('CBJ smart camera search subnet IP $subnet'); - - final Stream devicesWithPort = - HostScanner.scanDevicesForSinglePort( - subnet, - CbjSmartDeviceServerU.port, - - /// TODO: return this settings when can use with the await for loop - // resultsInIpAscendingOrder: false, - timeout: const Duration(milliseconds: 600), - ); - - await for (final ActiveHost activeHost in devicesWithPort) { - logger.i('Found CBJ Smart security camera: ${activeHost.address}'); - return right(activeHost.address); - } - } catch (e) { - logger.w('Exception searchForHub\n$e'); - } - - // TODO: Create support for all types - // final Future> mdnsDevices = - // CompaniesConnectorConjector.searchMdnsDevices(); - // - // final Future> pingableDevices = - // CompaniesConnectorConjector.searchPingableDevices(); - - // final List> socketBindingsList = - // CompaniesConnectorConjector.findDevicesByBindingIntoSockets(); - // - // final List listenToSocketBinding = []; - // for (final Stream socketBinding in socketBindingsList) { - // listenToSocketBinding.add( - // socketBinding.listen((switcherApiObject) { - // // TODO: Make it work with all types and not just SwitcherApiObject - // getIt() - // .addOnlyNewSwitcherDevice(switcherApiObject as SwitcherApiObject); - // }), - // ); - // } - // - // for (final StreamSubscription socketBindingSubscription - // in listenToSocketBinding) { - // await socketBindingSubscription.cancel(); - // } - - // try { - // for (final ActiveHost activeHost in await mdnsDevices) { - // CompaniesConnectorConjector.setMdnsDeviceByCompany(activeHost); - // } - // } catch (e) { - // logger.e('Mdns search error\n$e'); - // } - // - // for (final ActiveHost activeHost in await pingableDevices) { - // try { - // CompaniesConnectorConjector.setHostNameDeviceByCompany( - // activeHost: activeHost, - // ); - // } catch (e) { - // continue; - // } - // } r - - return left(const HubFailures.cantFindHubInNetwork()); - } } diff --git a/lib/infrastructure/mqtt/mqtt.dart b/lib/infrastructure/mqtt/mqtt.dart new file mode 100644 index 000000000..f0c009292 --- /dev/null +++ b/lib/infrastructure/mqtt/mqtt.dart @@ -0,0 +1,110 @@ +import 'package:cbj_integrations_controller/domain/mqtt_server/i_mqtt_server_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:mqtt_client/mqtt_client.dart'; +import 'package:mqtt_client/mqtt_server_client.dart'; +import 'package:mqtt_client/src/observable/src/records.dart'; + +class MqttServerRepository extends IMqttServerRepository { + MqttServerRepository() { + IMqttServerRepository.instance = this; + } + + @override + Future allHubDevicesSubscriptions() async {} + + @override + Future asyncConstractor() async {} + + @override + Future connect() async { + return MqttServerClient('', ''); + } + + @override + String getBindingsTopicTypeName() => ''; + + @override + String getDevicesTopicTypeName() => ''; + + @override + String getHubBaseTopic() => ''; + + @override + String getNodeRedApiBaseTopic() => ''; + + @override + String getNodeRedDevicesTopicTypeName() => ''; + + @override + String getRoutinesTopicTypeName() => ''; + + @override + String getScenesTopicTypeName() => ''; + + @override + Future postSmartDeviceToAppMqtt( + {required DeviceEntityAbstract entityFromTheHub}) async {} + + @override + Future postToAppMqtt( + {required DeviceEntityAbstract entityFromTheHub}) async {} + + @override + Future postToHubMqtt({ + required entityFromTheApp, + bool? gotFromApp, + }) async {} + + @override + Future publishDeviceEntity( + DeviceEntityAbstract deviceEntityDtoAbstract, + ) async {} + + @override + Future publishMessage(String topic, String message) async {} + + @override + Future?> readingFromMqttOnce(String topic) async { + return null; + } + + @override + Future sendToApp() async {} + + @override + Stream>> + streamOfAllDeviceAppSubscriptions() { + // TODO: implement streamOfAllDeviceAppSubscriptions + throw UnimplementedError(); + } + + @override + Stream>> + streamOfAllDevicesHubSubscriptions() { + // TODO: implement streamOfAllDevicesHubSubscriptions + throw UnimplementedError(); + } + + @override + Stream>> + streamOfAllHubSubscriptions() { + // TODO: implement streamOfAllHubSubscriptions + throw UnimplementedError(); + } + + @override + Stream>> streamOfAllSubscriptions() { + // TODO: implement streamOfAllSubscriptions + throw UnimplementedError(); + } + + @override + Stream>> streamOfChosenSubscription( + String topicPath) { + // TODO: implement streamOfChosenSubscription + throw UnimplementedError(); + } + + @override + Future subscribeToTopic(String topic) async {} +} diff --git a/lib/infrastructure/phone_hub/phone_hub.dart b/lib/infrastructure/phone_hub/phone_hub.dart new file mode 100644 index 000000000..c6c33ab2d --- /dev/null +++ b/lib/infrastructure/phone_hub/phone_hub.dart @@ -0,0 +1,98 @@ +import 'dart:async'; + +import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; +import 'package:cbj_integrations_controller/infrastructure/devices/companies_connector_conjector.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cbj_smart_device/application/usecases/smart_server_u/smart_server_u.dart'; +import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart'; +import 'package:network_info_plus/network_info_plus.dart'; +import 'package:network_tools/network_tools.dart'; + +class PhoneHub { + factory PhoneHub() { + return _instance; + } + + PhoneHub._singletonContractor(); + + static final PhoneHub _instance = PhoneHub._singletonContractor(); + + Future> get requestsAndStatusFromHub { + return ISavedDevicesRepo.instance.getAllDevices(); + } + + static Future searchDevices() async { + logger.i('Found searchDevices'); + final Either a = await _instance.searchCamera(); + a.fold( + (l) => logger.i('Found smart camera no'), + (r) => logger.i('Found smart camera'), + ); + CompaniesConnectorConjector.searchDevicesByBindingIntoSockets(); + + logger.i('Found searchDevices2'); + + // while (true) { + final Future> mdnsDevices = + CompaniesConnectorConjector.searchMdnsDevices(); + final Future> pingableDevices = + CompaniesConnectorConjector.searchPingableDevices(); + + final List mdnsDevicesTemp = await mdnsDevices; + if (mdnsDevicesTemp.isEmpty) { + logger.i('mdnsDevicesTemp is empty'); + } + for (final ActiveHost activeHost in mdnsDevicesTemp) { + print('activeHost $activeHost'); + CompaniesConnectorConjector.setMdnsDeviceByCompany(activeHost); + // } + + final List pingableDevicesTemp = await pingableDevices; + if (pingableDevicesTemp.isEmpty) { + logger.i('pingableDevicesTemp is empty'); + } + for (final ActiveHost activeHost in pingableDevicesTemp) { + print('activeHost2 $activeHost'); + CompaniesConnectorConjector.setHostNameDeviceByCompany( + activeHost: activeHost, + ); + } + } + } + + Future> searchCamera() async { + String? currentDeviceIP; + try { + final NetworkInfo networkInfo = NetworkInfo(); + currentDeviceIP = await networkInfo.getWifiIP(); + + if (currentDeviceIP == null) { + return left('off'); + } + + final String subnet = + currentDeviceIP.substring(0, currentDeviceIP.lastIndexOf('.')); + + logger.i('CBJ smart camera search subnet IP $subnet'); + + final Stream devicesWithPort = + HostScanner.scanDevicesForSinglePort( + subnet, + CbjSmartDeviceServerU.port, + + /// TODO: return this settings when can use with the await for loop + // resultsInIpAscendingOrder: false, + timeout: const Duration(milliseconds: 600), + ); + + await for (final ActiveHost activeHost in devicesWithPort) { + logger.i('Found CBJ Smart security camera: ${activeHost.address}'); + return right(activeHost.address); + } + } catch (e) { + logger.w('Exception searchForHub\n$e'); + } + return left('off'); + } +} diff --git a/lib/main.dart b/lib/main.dart index 8f410d3b3..279fef69d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,15 @@ import 'dart:io'; +import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.dart'; +import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/infrastructure/local_db/local_db_hive_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/system_commands/system_commands_manager_d.dart'; import 'package:cbj_integrations_controller/injection.dart'; import 'package:cybear_jinni/ad_state.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; +import 'package:cybear_jinni/infrastructure/commands/flutter_commands.dart'; +import 'package:cybear_jinni/infrastructure/mqtt/mqtt.dart'; +import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; import 'package:cybear_jinni/infrastructure/room/room_repository.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/app_widget.dart'; @@ -69,6 +75,12 @@ Future main() async { await configureLocalTimeZone(); await initialisationNotifications(); + MqttServerRepository(); + PhoneCommandsD(); + SystemCommandsManager(); + await ILocalDbRepository.instance.initializeDb(); + await ISavedDevicesRepo.instance.setUpAllFromDb(); + PhoneHub.searchDevices(); runApp( /// Use https://lingohub.com/developers/supported-locales/language-designators-with-regions From 225c8bd0aefb789e5b09481157a4d7fb96342c1c Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 25 Nov 2023 22:02:46 +0200 Subject: [PATCH 03/15] Can preview devices in home page without option to change state --- .../device_watcher/device_watcher_bloc.dart | 46 +++++++++++++++++-- .../hub_in_network/hub_in_network_bloc.dart | 3 +- .../commands/flutter_commands.dart | 6 --- lib/infrastructure/phone_hub/phone_hub.dart | 43 ----------------- pubspec.yaml | 6 ++- 5 files changed, 48 insertions(+), 56 deletions(-) diff --git a/lib/application/devices/device_watcher/device_watcher_bloc.dart b/lib/application/devices/device_watcher/device_watcher_bloc.dart index 03e95eb19..cee1ebfa9 100644 --- a/lib/application/devices/device_watcher/device_watcher_bloc.dart +++ b/lib/application/devices/device_watcher/device_watcher_bloc.dart @@ -4,9 +4,12 @@ import 'package:bloc/bloc.dart'; import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; +import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; +import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -18,14 +21,12 @@ part 'device_watcher_state.dart'; @injectable class DeviceWatcherBloc extends Bloc { - DeviceWatcherBloc() - : super(DeviceWatcherState.initial()) { + DeviceWatcherBloc() : super(DeviceWatcherState.initial()) { on(_watchAllStarted); on(_roomsReceived); on(_devicesReceived); } - KtList listOfDevices = [null].toImmutableList(); KtList listOfRooms = [null].toImmutableList(); @@ -34,6 +35,7 @@ class DeviceWatcherBloc extends Bloc { StreamSubscription>>? _deviceStreamSubscription; + late RoomEntity discoveredRoom; // // @override // Stream mapEventToState( @@ -92,13 +94,49 @@ class DeviceWatcherBloc extends Bloc { ) async { emit(const DeviceWatcherState.loadInProgress()); + discoveredRoom = RoomEntity( + uniqueId: + RoomUniqueId.fromUniqueString('00000000-0000-0000-0000-000000000000'), + cbjEntityName: RoomDefaultName('Discovered'), + roomTypes: RoomTypes(const []), + roomDevicesId: RoomDevicesId(const []), + roomScenesId: RoomScenesId(const []), + roomRoutinesId: RoomRoutinesId(const []), + roomBindingsId: RoomBindingsId(const []), + roomMostUsedBy: RoomMostUsedBy(const []), + roomPermissions: RoomPermissions(const []), + background: RoomBackground( + 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', + ), + ); + + final Map allDevice = + await PhoneHub().requestsAndStatusFromHub; + logger.i('Getting all devices $allDevice'); + + for (final String deviceId in allDevice.keys) { + discoveredRoom.addDeviceId(deviceId); + } + + add( + DeviceWatcherEvent.roomsReceived( + right([discoveredRoom].toImmutableList()), + ), + ); + + add( + DeviceWatcherEvent.devicesReceived( + right(allDevice.values.toImmutableList()), + ), + ); + _roomStreamSubscription = IRoomRepository.instance.watchAllRooms().listen((eventWatch) { add(DeviceWatcherEvent.roomsReceived(eventWatch)); }); _deviceStreamSubscription = - IDeviceRepository.instance.watchAllDevices().listen((eventWatch) { + IDeviceRepository.instance.watchAllDevices().listen((eventWatch) { add(DeviceWatcherEvent.devicesReceived(eventWatch)); }); } diff --git a/lib/application/hub_in_network/hub_in_network_bloc.dart b/lib/application/hub_in_network/hub_in_network_bloc.dart index ee303aee0..22c1b61c5 100644 --- a/lib/application/hub_in_network/hub_in_network_bloc.dart +++ b/lib/application/hub_in_network/hub_in_network_bloc.dart @@ -61,7 +61,8 @@ class HubInNetworkBloc extends Bloc { return HubInNetworkState.loadFailure(l); } logger.i('All Devices smartDevices $smartDevices'); - return const HubInNetworkState.loadSuccessSecurityCamera(''); + context?.router.replace(const HomeRoute()); + return const HubInNetworkState.loadSuccess(); }, (r) { context?.router.replace(const HomeRoute()); return const HubInNetworkState.loadSuccess(); diff --git a/lib/infrastructure/commands/flutter_commands.dart b/lib/infrastructure/commands/flutter_commands.dart index 2353e0ae0..e3480c6cb 100644 --- a/lib/infrastructure/commands/flutter_commands.dart +++ b/lib/infrastructure/commands/flutter_commands.dart @@ -64,12 +64,6 @@ class PhoneCommandsD implements IPhoneCommandsD { return Directory.current.path; } - @override - Future getIpFromMdnsName(String mdnsName) async { - // TODO: implement getIpFromMdnsName - throw UnimplementedError(); - } - @override Future suspendComputer() { // TODO: implement goToSleep diff --git a/lib/infrastructure/phone_hub/phone_hub.dart b/lib/infrastructure/phone_hub/phone_hub.dart index c6c33ab2d..0a9460019 100644 --- a/lib/infrastructure/phone_hub/phone_hub.dart +++ b/lib/infrastructure/phone_hub/phone_hub.dart @@ -3,10 +3,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/companies_connector_conjector.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_smart_device/application/usecases/smart_server_u/smart_server_u.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:dartz/dartz.dart'; -import 'package:network_info_plus/network_info_plus.dart'; import 'package:network_tools/network_tools.dart'; class PhoneHub { @@ -24,11 +21,6 @@ class PhoneHub { static Future searchDevices() async { logger.i('Found searchDevices'); - final Either a = await _instance.searchCamera(); - a.fold( - (l) => logger.i('Found smart camera no'), - (r) => logger.i('Found smart camera'), - ); CompaniesConnectorConjector.searchDevicesByBindingIntoSockets(); logger.i('Found searchDevices2'); @@ -60,39 +52,4 @@ class PhoneHub { } } } - - Future> searchCamera() async { - String? currentDeviceIP; - try { - final NetworkInfo networkInfo = NetworkInfo(); - currentDeviceIP = await networkInfo.getWifiIP(); - - if (currentDeviceIP == null) { - return left('off'); - } - - final String subnet = - currentDeviceIP.substring(0, currentDeviceIP.lastIndexOf('.')); - - logger.i('CBJ smart camera search subnet IP $subnet'); - - final Stream devicesWithPort = - HostScanner.scanDevicesForSinglePort( - subnet, - CbjSmartDeviceServerU.port, - - /// TODO: return this settings when can use with the await for loop - // resultsInIpAscendingOrder: false, - timeout: const Duration(milliseconds: 600), - ); - - await for (final ActiveHost activeHost in devicesWithPort) { - logger.i('Found CBJ Smart security camera: ${activeHost.address}'); - return right(activeHost.address); - } - } catch (e) { - logger.w('Exception searchForHub\n$e'); - } - return left('off'); - } } diff --git a/pubspec.yaml b/pubspec.yaml index a6b68516d..eac6fbc2c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,9 +46,11 @@ dependencies: # Helps implement the BLoC pattern. bloc: ^8.1.2 cbj_integrations_controller: - git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git + path: ../cbj_integrations_controller +# git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git cbj_smart_device_flutter: - git: https://github.com/CyBear-Jinni/cbj_smart_device_flutter.git + path: ../cbj_smart_device_flutter +# git: https://github.com/CyBear-Jinni/cbj_smart_device_flutter.git # Copy text from and to clipboard clipboard: ^0.1.3 # Package to create, convert, alter, and compare colors in a variety of colorspaces. From 9523dece3e2858496188794a21ed4550a7eab25a Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sun, 26 Nov 2023 00:36:30 +0200 Subject: [PATCH 04/15] App turn blinds down successfully without hub --- .../device_watcher/device_watcher_bloc.dart | 4 +-- .../hub_in_network/hub_in_network_bloc.dart | 6 +++- .../devices/device/device_repository.dart | 3 +- lib/infrastructure/hub_client/hub_client.dart | 4 +-- lib/infrastructure/mqtt/mqtt.dart | 18 +++++++++-- lib/infrastructure/phone_hub/phone_hub.dart | 30 ++++++++++++++++++- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/lib/application/devices/device_watcher/device_watcher_bloc.dart b/lib/application/devices/device_watcher/device_watcher_bloc.dart index cee1ebfa9..2255495c3 100644 --- a/lib/application/devices/device_watcher/device_watcher_bloc.dart +++ b/lib/application/devices/device_watcher/device_watcher_bloc.dart @@ -9,7 +9,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; -import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -111,8 +110,7 @@ class DeviceWatcherBloc extends Bloc { ); final Map allDevice = - await PhoneHub().requestsAndStatusFromHub; - logger.i('Getting all devices $allDevice'); + await PhoneHub().getAllDevices; for (final String deviceId in allDevice.keys) { discoveredRoom.addDeviceId(deviceId); diff --git a/lib/application/hub_in_network/hub_in_network_bloc.dart b/lib/application/hub_in_network/hub_in_network_bloc.dart index 22c1b61c5..c1b1073ad 100644 --- a/lib/application/hub_in_network/hub_in_network_bloc.dart +++ b/lib/application/hub_in_network/hub_in_network_bloc.dart @@ -56,10 +56,12 @@ class HubInNetworkBloc extends Bloc { final PhoneHub phoneHub = PhoneHub(); final Map smartDevices = - await phoneHub.requestsAndStatusFromHub; + await phoneHub.getAllDevices; if (smartDevices.isEmpty) { return HubInNetworkState.loadFailure(l); } + await IHubConnectionRepository.instance.closeConnection(); + phoneHub.startListen(); logger.i('All Devices smartDevices $smartDevices'); context?.router.replace(const HomeRoute()); return const HubInNetworkState.loadSuccess(); @@ -110,6 +112,8 @@ class HubInNetworkBloc extends Bloc { ); return; } + await IHubConnectionRepository.instance.closeConnection(); + event.context.router.push(const SmartCameraContainerRoute()); } diff --git a/lib/infrastructure/devices/device/device_repository.dart b/lib/infrastructure/devices/device/device_repository.dart index 01b755d5a..3e45714fb 100644 --- a/lib/infrastructure/devices/device/device_repository.dart +++ b/lib/infrastructure/devices/device/device_repository.dart @@ -31,7 +31,6 @@ import 'package:cybear_jinni/domain/user/i_user_repository.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_requests_routing.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:device_info_plus/device_info_plus.dart'; @@ -81,7 +80,7 @@ class DeviceRepository implements IDeviceRepository { @override Future initiateHubConnection() async { AppRequestsToHub.listenToApp(); - HubRequestsToApp.lisenToApp(); + HubRequestsToApp.listenToApp(); HubRequestRouting.navigateRequest(); } diff --git a/lib/infrastructure/hub_client/hub_client.dart b/lib/infrastructure/hub_client/hub_client.dart index a350fe66b..39811799e 100644 --- a/lib/infrastructure/hub_client/hub_client.dart +++ b/lib/infrastructure/hub_client/hub_client.dart @@ -72,7 +72,7 @@ class HubClient { /// Requests and updates from hub to the app class HubRequestsToApp { /// Stream of the requests from the hub - /// Broadcast can be lisent multiple times + /// Broadcast can be listen multiple times static StreamGroup hubRequestsStreamBroadcast = StreamGroup.broadcast(); @@ -82,7 +82,7 @@ class HubRequestsToApp { static final hubRequestsStreamController = StreamController(); - static Future lisenToApp() async { + static Future listenToApp() async { if (boolListenWorking) { return; } diff --git a/lib/infrastructure/mqtt/mqtt.dart b/lib/infrastructure/mqtt/mqtt.dart index f0c009292..03af85e95 100644 --- a/lib/infrastructure/mqtt/mqtt.dart +++ b/lib/infrastructure/mqtt/mqtt.dart @@ -1,5 +1,8 @@ import 'package:cbj_integrations_controller/domain/mqtt_server/i_mqtt_server_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper.dart'; +import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; import 'package:mqtt_client/src/observable/src/records.dart'; @@ -42,8 +45,17 @@ class MqttServerRepository extends IMqttServerRepository { String getScenesTopicTypeName() => ''; @override - Future postSmartDeviceToAppMqtt( - {required DeviceEntityAbstract entityFromTheHub}) async {} + Future postSmartDeviceToAppMqtt({ + required DeviceEntityAbstract entityFromTheHub, + }) async { + HubRequestsToApp.hubRequestsStreamController.sink.add( + RequestsAndStatusFromHub( + sendingType: SendingType.entityType, + allRemoteCommands: + DeviceHelper.convertDomainToJsonString(entityFromTheHub), + ), + ); + } @override Future postToAppMqtt( @@ -51,7 +63,7 @@ class MqttServerRepository extends IMqttServerRepository { @override Future postToHubMqtt({ - required entityFromTheApp, + required dynamic entityFromTheApp, bool? gotFromApp, }) async {} diff --git a/lib/infrastructure/phone_hub/phone_hub.dart b/lib/infrastructure/phone_hub/phone_hub.dart index 0a9460019..d96eb8876 100644 --- a/lib/infrastructure/phone_hub/phone_hub.dart +++ b/lib/infrastructure/phone_hub/phone_hub.dart @@ -2,7 +2,11 @@ import 'dart:async'; import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/companies_connector_conjector.dart'; +import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.dart'; +import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; +import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:network_tools/network_tools.dart'; @@ -15,7 +19,9 @@ class PhoneHub { static final PhoneHub _instance = PhoneHub._singletonContractor(); - Future> get requestsAndStatusFromHub { + bool phoneAsHub = false; + + Future> get getAllDevices { return ISavedDevicesRepo.instance.getAllDevices(); } @@ -52,4 +58,26 @@ class PhoneHub { } } } + + startListen() { + phoneAsHub = true; + CompaniesConnectorConjector.updateAllDevicesReposWithDeviceChanges( + AppRequestsToHub.appRequestsToHubStreamController.stream + .map((clientStatusRequests) { + if (!phoneAsHub) { + return ''; + } + dynamic dtosEntity = + DeviceHelperMethods.clientStatusRequestsToItsDtosType( + clientStatusRequests, + ); + if (dtosEntity is DeviceEntityAbstract) { + dtosEntity.entityStateGRPC = + EntityState(EntityStateGRPC.waitingInComp.toString()); + return dtosEntity; + } + return ''; + }), + ); + } } From 4b62ba24eac7d4c4ce92fd814fe9c377364fa026 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Mon, 27 Nov 2023 00:01:14 +0200 Subject: [PATCH 05/15] wip adding camera support to devices UI --- .../commands/flutter_commands.dart | 78 --------------- .../hub_client/hub_requests_routing.dart | 9 +- lib/main.dart | 4 +- .../rooms_widgets/rom_widget.dart | 12 +++ .../widgets/plus_button_wighet.dart | 97 ++++++++++++++++--- 5 files changed, 107 insertions(+), 93 deletions(-) delete mode 100644 lib/infrastructure/commands/flutter_commands.dart diff --git a/lib/infrastructure/commands/flutter_commands.dart b/lib/infrastructure/commands/flutter_commands.dart deleted file mode 100644 index e3480c6cb..000000000 --- a/lib/infrastructure/commands/flutter_commands.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'dart:io'; - -import 'package:cbj_integrations_controller/infrastructure/system_commands/phone_commands_d/common_batch_commands_d.dart'; -import 'package:path_provider/path_provider.dart'; - -class PhoneCommandsD implements IPhoneCommandsD { - PhoneCommandsD() { - IPhoneCommandsD.instance = this; - } - - String? currentUserName; - String? currentDriveLetter; - - @override - Future getCurrentUserName() async { - return 'cbj_app'; - } - - @override - Future getUuidOfCurrentDevice() async { - return '000000000'; - } - - @override - Future getDeviceHostName() async { - return ''; - } - - @override - Future getAllEtcReleaseFilesText() { - //TODO: add implementation, for now will return getDeviceHostName - return getDeviceHostName(); - } - - @override - Future getFileContent(String fileFullPath) async { - throw UnimplementedError(); - } - - @override - Future getDeviceConfiguration() async { - return ''; - } - - Future getCurrentDriveLetter() async { - return ''; - } - - //TODO: Currently does not work as echo %~dp0 will not work at the command - // line, only in a batch file. - Future getOsDriveLetter() async { - return ''; - } - - @override - Future getLocalDbPath( - Future currentUserName, - ) async { - return (await getApplicationDocumentsDirectory()).path; - } - - @override - Future getProjectFilesLocation() async { - return Directory.current.path; - } - - @override - Future suspendComputer() { - // TODO: implement goToSleep - throw UnimplementedError(); - } - - @override - Future shutdownComputer() { - // TODO: implement shutdownComputer - throw UnimplementedError(); - } -} diff --git a/lib/infrastructure/hub_client/hub_requests_routing.dart b/lib/infrastructure/hub_client/hub_requests_routing.dart index fd03a85bd..98936a49d 100644 --- a/lib/infrastructure/hub_client/hub_requests_routing.dart +++ b/lib/infrastructure/hub_client/hub_requests_routing.dart @@ -14,6 +14,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_ping_device/generic_ping_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_device_dtos.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_security_camera_device/generic_security_camera_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv_device/generic_smart_tv_device_dtos.dart'; @@ -203,6 +204,10 @@ class HubRequestRouting { deviceEntity = GenericPrinterDeviceDtos.fromJson(requestAsJson).toDomain(); logger.i('Adding Smart printer device type'); + case EntityTypes.securityCamera: + deviceEntity = + GenericSecurityCameraDeviceDtos.fromJson(requestAsJson).toDomain(); + logger.i('Adding Smart camera device type'); default: if (entityStateGRPC == EntityStateGRPC.pingNow) { deviceEntity = @@ -210,11 +215,11 @@ class HubRequestRouting { logger.t('Got Ping request'); return; } else { - deviceEntity = - GenericEmptyDeviceDtos.fromJson(requestAsJson).toDomain(); logger.w( 'Device type is $deviceType is not supported $entityStateGRPC ', ); + deviceEntity = + GenericEmptyDeviceDtos.fromJson(requestAsJson).toDomain(); } break; } diff --git a/lib/main.dart b/lib/main.dart index 279fef69d..9d9a1d93f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,11 +3,12 @@ import 'dart:io'; import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.dart'; import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/infrastructure/local_db/local_db_hive_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/node_red/node_red_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/system_commands/system_commands_manager_d.dart'; import 'package:cbj_integrations_controller/injection.dart'; +import 'package:cbj_smart_device_flutter/commands/flutter_commands.dart'; import 'package:cybear_jinni/ad_state.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/infrastructure/commands/flutter_commands.dart'; import 'package:cybear_jinni/infrastructure/mqtt/mqtt.dart'; import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; import 'package:cybear_jinni/infrastructure/room/room_repository.dart'; @@ -78,6 +79,7 @@ Future main() async { MqttServerRepository(); PhoneCommandsD(); SystemCommandsManager(); + NodeRedRepository(); await ILocalDbRepository.instance.initializeDb(); await ISavedDevicesRepo.instance.setUpAllFromDb(); PhoneHub.searchDevices(); diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart index d4dda5554..6f35ade31 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart @@ -270,6 +270,18 @@ class RoomWidget extends StatelessWidget { tempRoomColorGradiant: roomColorGradiant, ), ); + } else if (deviceType == + EntityTypes.securityCamera.toString()) { + return BlocProvider( + create: (context) => getIt(), + child: PrintersInTheRoomBlock.withAbstractDevice( + roomEntityTemp: roomsList.firstWhere( + (element) => element!.uniqueId.getOrCrash() == roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: roomColorGradiant, + ), + ); } logger.w('Arrived here unsupported device type $deviceType'); diff --git a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart index d7eb85b5a..05593e367 100644 --- a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart +++ b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart @@ -41,11 +41,9 @@ class PlusButtonWidget extends StatelessWidget { color: Colors.white, child: Column( children: [ - const SizedBox( - height: 1, - ), + const SizedBox(height: 1), ColoredBox( - color: Colors.purple.withOpacity(0.7), + color: Colors.indigoAccent.withOpacity(0.7), child: ListTile( leading: FaIcon( FontAwesomeIcons.sitemap, @@ -54,7 +52,7 @@ class PlusButtonWidget extends StatelessWidget { size: 25, ), title: Text( - 'Add Automation', + 'Turn Phone To a Security Camera', style: TextStyle( color: Theme.of(context) .textTheme @@ -62,9 +60,12 @@ class PlusButtonWidget extends StatelessWidget { .color, ), ), - onTap: () { + onTap: () async { + await IHubConnectionRepository.instance + .closeConnection(); + context.router - .push(const ChooseAutomationTypeToAddRoute()); + .push(const SmartCameraContainerRoute()); }, ), ), @@ -95,9 +96,7 @@ class PlusButtonWidget extends StatelessWidget { }, ), ), - const SizedBox( - height: 1, - ), + const SizedBox(height: 1), ColoredBox( color: Colors.blue, child: ListTile( @@ -121,9 +120,32 @@ class PlusButtonWidget extends StatelessWidget { }, ), ), - const SizedBox( - height: 1, + const SizedBox(height: 1), + ColoredBox( + color: Colors.purple.withOpacity(0.7), + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.sitemap, + color: + Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: Text( + 'Add Automation', + style: TextStyle( + color: Theme.of(context) + .textTheme + .bodyLarge! + .color, + ), + ), + onTap: () { + context.router + .push(const ChooseAutomationTypeToAddRoute()); + }, + ), ), + const SizedBox(height: 1), ], ), ), @@ -267,3 +289,54 @@ class PlusButtonWidget extends StatelessWidget { ); } } + +// +// GestureDetector( +// onTap: () { +// +// await IHubConnectionRepository.instance.closeConnection(); +// +// event.context.router.push(const SmartCameraContainerRoute()); +// }, +// child: Container( +// margin: const EdgeInsets.symmetric(horizontal: 30), +// height: 60, +// color: HexColor('#985dc7'), +// child: Container( +// margin: const EdgeInsets.symmetric(horizontal: 15), +// child: Row( +// children: [ +// const FaIcon( +// FontAwesomeIcons.camera, +// color: Colors.white, +// ), +// const SizedBox( +// width: 40, +// ), +// Flexible( +// child: RichText( +// text: TextSpan( +// style: TextStyle( +// color: Colors.white.withOpacity(0.9), +// ), +// children: const [ +// TextSpan( +// text: 'Security Camera\n', +// style: TextStyle(fontSize: 16), +// ), +// TextSpan( +// text: +// 'Transform your phone into a smart security camera', +// style: TextStyle( +// color: Colors.white, +// ), +// ), +// ], +// ), +// ), +// ), +// ], +// ), +// ), +// ), +// ), From 56b78116d93ebfb5feb08906c531967f7d886a3a Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Wed, 29 Nov 2023 18:52:02 +0200 Subject: [PATCH 06/15] Added support viewing camera in home page --- .../security_camera_actor_bloc.dart | 97 +++++++++++ .../security_camera_actor_event.dart | 29 ++++ .../security_camera_actor_state.dart | 15 ++ .../security_camera_watcher_bloc.dart | 59 +++++++ .../security_camera_watcher_event.dart | 10 ++ .../security_camera_watcher_state.dart | 19 +++ .../security_cameras_in_the_room_block.dart | 158 ++++++++++++++++++ .../rooms_widgets/rom_widget.dart | 6 +- 8 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart create mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart create mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart create mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart create mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart create mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart create mode 100644 lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart new file mode 100644 index 000000000..56904b660 --- /dev/null +++ b/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart @@ -0,0 +1,97 @@ +import 'dart:async'; + +import 'package:another_flushbar/flushbar_helper.dart'; +import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_security_camera_device/generic_security_camera_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:injectable/injectable.dart'; +import 'package:url_launcher/url_launcher.dart'; + +part 'security_camera_actor_bloc.freezed.dart'; +part 'security_camera_actor_event.dart'; +part 'security_camera_actor_state.dart'; + +@injectable +class SecurityCamerasActorBloc + extends Bloc { + SecurityCamerasActorBloc() + : super(const SecurityCamerasActorState.initial()) { + on(_initialized); + on(_deleted); + on(_turnOffAllSecurityCameras); + on(_turnOnAllSecurityCameras); + on(_openSecurityCamerasWebPage); + on(_shutdownAllSecurityCameras); + } + + Future _initialized( + Initialized event, + Emitter emit, + ) async {} + + Future _deleted( + Deleted event, + Emitter emit, + ) async {} + + Future _turnOffAllSecurityCameras( + TurnOffAllSecurityCameras event, + Emitter emit, + ) async { + FlushbarHelper.createLoading( + message: 'Turning Off all Smart Computers', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(event.context); + + IDeviceRepository.instance.turnOffDevices( + devicesId: event.securityCamerasIdToTurnOff, + ); + } + + Future _turnOnAllSecurityCameras( + TurnOnAllSecurityCameras event, + Emitter emit, + ) async { + FlushbarHelper.createLoading( + message: 'Turning On all Smart Computers', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(event.context); + + IDeviceRepository.instance + .turnOnDevices(devicesId: event.securityCamerasIdToTurnOn); + } + + Future _openSecurityCamerasWebPage( + OpenSecurityCamerasWebPage event, + Emitter emit, + ) async { + FlushbarHelper.createLoading( + message: 'Opening securityCameras Web Page', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(event.context); + + final String securityCameraIp = + event.securityCamera.deviceLastKnownIp.getOrCrash(); + launchUrl( + Uri.parse('http://$securityCameraIp'), + mode: LaunchMode.externalApplication, + ); + } + + Future _shutdownAllSecurityCameras( + ShutdownAllSecurityCameras event, + Emitter emit, + ) async { + FlushbarHelper.createLoading( + message: 'Suspending all Smart Computers', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(event.context); + + IDeviceRepository.instance + .shutdownDevices(devicesId: event.securityCamerasId); + } +} diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart new file mode 100644 index 000000000..e5d7affa7 --- /dev/null +++ b/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart @@ -0,0 +1,29 @@ +part of 'security_camera_actor_bloc.dart'; + +@freezed +class SecurityCamerasActorEvent with _$SecurityCamerasActorEvent { + const factory SecurityCamerasActorEvent.initialized() = Initialized; + + const factory SecurityCamerasActorEvent.turnOffAllSecurityCameras( + List securityCamerasIdToTurnOff, + BuildContext context, + ) = TurnOffAllSecurityCameras; + + const factory SecurityCamerasActorEvent.turnOnAllSecurityCameras( + List securityCamerasIdToTurnOn, + BuildContext context, + ) = TurnOnAllSecurityCameras; + + const factory SecurityCamerasActorEvent.openSecurityCamerasWebPage( + GenericSecurityCameraDE securityCamera, + BuildContext context, + ) = OpenSecurityCamerasWebPage; + + const factory SecurityCamerasActorEvent.shutdownAllSecurityCameras( + List securityCamerasId, + BuildContext context, + ) = ShutdownAllSecurityCameras; + + const factory SecurityCamerasActorEvent.deleted( + GenericSwitchDE deviceEntity) = Deleted; +} diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart new file mode 100644 index 000000000..0e4cea548 --- /dev/null +++ b/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart @@ -0,0 +1,15 @@ +part of 'security_camera_actor_bloc.dart'; + +@freezed +class SecurityCamerasActorState with _$SecurityCamerasActorState { + const factory SecurityCamerasActorState.initial() = _Initial; + + const factory SecurityCamerasActorState.actionInProgress() = + _ActionInProgress; + + const factory SecurityCamerasActorState.deleteFailure( + DevicesFailure devicesFailure, + ) = _DeleteFailure; + + const factory SecurityCamerasActorState.deleteSuccess() = _DeleteSuccess; +} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart new file mode 100644 index 000000000..dbd0249c8 --- /dev/null +++ b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart @@ -0,0 +1,59 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:dartz/dartz.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:injectable/injectable.dart'; +import 'package:kt_dart/kt.dart'; + +part 'security_camera_watcher_bloc.freezed.dart'; +part 'security_camera_watcher_event.dart'; +part 'security_camera_watcher_state.dart'; + +@injectable +class SecurityCamerasWatcherBloc + extends Bloc { + SecurityCamerasWatcherBloc() : super(SecurityCamerasWatcherState.initial()) { + on(_watchAllStarted); + on(_devicesReceived); + } + + StreamSubscription>>? + _deviceStreamSubscription; + + Future _watchAllStarted( + WatchAllStarted event, + Emitter emit, + ) async { + emit(const SecurityCamerasWatcherState.loadInProgress()); + await _deviceStreamSubscription?.cancel(); + // _deviceStreamSubscription = + // IDeviceRepository.instance.watchSecurityCameras().listen( + // (eventWatch) => + // add(SecurityCamerasWatcherEvent.devicesReceived(eventWatch)), + // ); + } + + Future _devicesReceived( + DevicesReceived event, + Emitter emit, + ) async { + emit(const SecurityCamerasWatcherState.loadInProgress()); + emit( + event.failureOrDevices.fold( + (f) => SecurityCamerasWatcherState.loadFailure(f), + (d) => SecurityCamerasWatcherState.loadSuccess( + d.map((v) => v!).toMutableList(), + ), + ), + ); + } + + @override + Future close() async { + await _deviceStreamSubscription?.cancel(); + return super.close(); + } +} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart new file mode 100644 index 000000000..47ea38a46 --- /dev/null +++ b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart @@ -0,0 +1,10 @@ +part of 'security_camera_watcher_bloc.dart'; + +@freezed +class SecurityCamerasWatcherEvent with _$SecurityCamerasWatcherEvent { + const factory SecurityCamerasWatcherEvent.watchAllStarted() = WatchAllStarted; + + const factory SecurityCamerasWatcherEvent.devicesReceived( + Either> failureOrDevices, + ) = DevicesReceived; +} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart new file mode 100644 index 000000000..68b1c7b00 --- /dev/null +++ b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart @@ -0,0 +1,19 @@ +part of 'security_camera_watcher_bloc.dart'; + +@freezed +class SecurityCamerasWatcherState with _$SecurityCamerasWatcherState { + factory SecurityCamerasWatcherState.initial() = _Initial; + + const factory SecurityCamerasWatcherState.loadInProgress() = _LoadInProgress; + + const factory SecurityCamerasWatcherState.loadSuccess( + KtList devices, + ) = _loadSuccess; + + const factory SecurityCamerasWatcherState.loadFailure( + DevicesFailure devicesFailure, + ) = _loadFailure; + + const factory SecurityCamerasWatcherState.securityCamerasError() = + SecurityCamerasError; +} diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart new file mode 100644 index 000000000..77342ae28 --- /dev/null +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart @@ -0,0 +1,158 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:auto_size_text/auto_size_text.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_security_camera_device/generic_security_camera_entity.dart'; +import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; +import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; + +class SecurityCamerasInTheRoomBlock extends StatelessWidget { + const SecurityCamerasInTheRoomBlock({ + required this.roomEntity, + required this.securityCamerasInRoom, + required this.roomColorGradiant, + }); + + factory SecurityCamerasInTheRoomBlock.withAbstractDevice({ + required RoomEntity roomEntityTemp, + required List tempDeviceInRoom, + required ListOfColors tempRoomColorGradiant, + }) { + final List tempSecurityCamerasInRoom = []; + + for (final element in tempDeviceInRoom) { + tempSecurityCamerasInRoom.add(element as GenericSecurityCameraDE); + } + + return SecurityCamerasInTheRoomBlock( + roomEntity: roomEntityTemp, + securityCamerasInRoom: tempSecurityCamerasInRoom, + roomColorGradiant: tempRoomColorGradiant, + ); + } + + final RoomEntity roomEntity; + final List securityCamerasInRoom; + final ListOfColors roomColorGradiant; + + @override + Widget build(BuildContext context) { + String deviceText; + if (securityCamerasInRoom.length == 1) { + deviceText = securityCamerasInRoom[0].cbjEntityName.getOrCrash()!; + } else { + deviceText = + '_SecurityCameras'.tr(args: [roomEntity.cbjEntityName.getOrCrash()]); + } + + return GestureDetector( + onTap: () { + context.router.push(VideoStreamOutputContainerRoute( + streamAddress: + securityCamerasInRoom.first.deviceLastKnownIp.getOrCrash())); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.amber.withOpacity(0.03), + borderRadius: const BorderRadius.all(Radius.circular(20)), + ), + margin: const EdgeInsets.symmetric(horizontal: 5), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Expanded(child: Text('')), + Expanded( + child: Column( + children: [ + const SizedBox(height: 10), + Transform.scale( + scale: 1.2, + child: const CircleAvatar( + child: FaIcon( + FontAwesomeIcons.print, + color: Colors.white70, + ), + ), + ), + ], + ), + ), + if (securityCamerasInRoom.length > 1) + Expanded( + child: Container( + height: 55, + alignment: Alignment.topLeft, + child: Container( + width: 28, + decoration: BoxDecoration( + border: Border.all( + color: Theme.of(context) + .textTheme + .bodyLarge! + .color! + .withOpacity(0.5), + ), + borderRadius: BorderRadius.circular(10), + ), + child: Text( + securityCamerasInRoom.length.toString(), + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 13, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ), + ) + else + const Expanded(child: Text('')), + ], + ), + const SizedBox(height: 5), + Stack( + children: [ + AutoSizeText( + deviceText, + maxLines: 1, + textAlign: TextAlign.center, + style: TextStyle( + foreground: Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 0.8 + ..color = Colors.black38, + ), + ), + AutoSizeText( + deviceText, + textAlign: TextAlign.center, + maxLines: 1, + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + ], + ), + ), + ); + } + + List extractDevicesId() { + final List devicesIdList = []; + for (final element in securityCamerasInRoom) { + devicesIdList.add(element.uniqueId.getOrCrash()); + } + return devicesIdList; + } +} diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart index 6f35ade31..4cd195763 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart @@ -5,6 +5,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; import 'package:cybear_jinni/application/lights/lights_actor/lights_actor_bloc.dart'; import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; +import 'package:cybear_jinni/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; @@ -15,6 +16,7 @@ import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/printers_in_the_room_block.dart'; +import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_computers_in_the_room_block.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart'; @@ -273,8 +275,8 @@ class RoomWidget extends StatelessWidget { } else if (deviceType == EntityTypes.securityCamera.toString()) { return BlocProvider( - create: (context) => getIt(), - child: PrintersInTheRoomBlock.withAbstractDevice( + create: (context) => getIt(), + child: SecurityCamerasInTheRoomBlock.withAbstractDevice( roomEntityTemp: roomsList.firstWhere( (element) => element!.uniqueId.getOrCrash() == roomId, )!, From e9d673004d30e9f9f7acac53ce410e0a873a94da Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Thu, 30 Nov 2023 17:36:54 +0200 Subject: [PATCH 07/15] Adding atoms --- lib/application/auth/auth_bloc.dart | 10 ------ lib/application/auth/auth_event.dart | 2 -- lib/presentation/atoms/atoms.dart | 2 ++ lib/presentation/atoms/image_atom.dart | 20 +++++++++++ lib/presentation/atoms/text_atom.dart | 34 +++++++++++++++++++ .../core/devices_cards/blinds_card.dart | 3 +- lib/presentation/core/theme_data.dart | 4 +-- .../{atoms/empty => molecules/molecules.dart} | 0 lib/presentation/organisms/empty | 0 .../empty => organisms/organisms.dart} | 0 .../widgets/action_choose_information.dart | 23 +++++++------ .../widgets/add_binding_widget.dart | 17 +++++----- .../pick_repeat_time_page.dart | 7 ++-- .../widgets/add_routine_widget.dart | 19 ++++++----- .../add_scene/widgets/add_scene_widget.dart | 17 +++++----- .../choose_automation_type_to_add_page.dart | 27 ++++++++------- .../add_new_devices/add_new_cbj_devices.dart | 3 +- .../smart_device_to_configure.dart | 5 +-- .../choose_device_vendor_to_add_page.dart | 5 +-- .../widgets/vendor_widget.dart | 5 +-- .../widgets/vendors_list.dart | 7 ++-- .../computer_connection_check_widget.dart | 15 ++++---- .../configure_new_cbj_comp_widget.dart | 23 +++++++------ .../connect_to_home_wifi_page.dart | 3 +- .../widgets/connect_to_home_wifi_widget.dart | 15 ++++---- .../open_access_pointi_page.dart | 3 +- .../widgets/open_access_point_widget.dart | 29 ++++++++-------- .../widgets/cbj_comp_card.dart | 11 +++--- .../cbj_comp_card_with_devices_controll.dart | 19 ++++++----- .../scan_for_new_cbj_comps_widget.dart | 11 +++--- .../pages/add_new_room/add_new_room_page.dart | 3 +- .../widgets/add_new_room_form.dart | 5 +-- .../add_user_to_home_page.dart | 3 +- .../widgets/add_user_to_home_widget.dart | 24 +++++++------ .../add_esphome_vendor_page.dart | 3 +- .../widgets/esphome_sign_in_form.dart | 8 ++--- .../add_ewelink_vendor_page.dart | 5 +-- .../widgets/ewelink_sign_in_form.dart | 8 ++--- .../add_jinvoo_smart_vendor_page.dart | 5 +-- .../widgets/jinvoo_smart_sign_in_form.dart | 14 ++++---- .../add_lifx_vendor/add_lifx_vendor_page.dart | 5 +-- .../widgets/lifx_sign_in_form.dart | 12 +++---- .../add_smart_life_vendor_page.dart | 5 +-- .../widgets/smart_life_sign_in_form.dart | 14 ++++---- .../add_tuya_vendor/add_tuya_vendor_page.dart | 5 +-- .../widgets/tuya_sign_in_form.dart | 14 ++++---- .../add_xiaomi_mi_vendor_page.dart | 5 +-- .../widgets/xiaomi_mi_sign_in_form.dart | 9 +++-- .../change_room_for_devices_widget.dart | 13 +++---- .../connect_to_hub/connect_to_hub_page.dart | 7 ++-- .../widgets/cbj_hub_in_network_widget.dart | 31 +++++++++-------- .../connect_to_hub_more_page.dart | 5 +-- .../widgets/connect_to_hub_more_widget.dart | 9 ++--- .../pages/create_home/create_home_page.dart | 3 +- .../widgets/create_home_widget.dart | 15 ++++---- .../blinds_in_the_room_page.dart | 2 +- .../blinds_in_the_room_widget.dart | 3 +- .../blinds/rooms_blinds_page.dart | 5 ++- .../blinds/settings_page_of_blinds.dart | 12 ++++--- .../blinds/smart_blind_widget.dart | 3 +- .../blinds/widgets/blind_widget.dart | 19 +++++------ ...ritical_failure_blinds_display_widget.dart | 7 ++-- .../widgets/error_blind_card_widget.dart | 7 ++-- .../blinds/widgets/room_blinds.dart | 3 +- .../widgets/room_blinds_toggles_block.dart | 3 +- .../blinds/widgets/rooms_blinds_widget.dart | 7 ++-- .../boilers_in_the_room_page.dart | 2 +- .../boilers_in_the_room_widget.dart | 3 +- .../boilers/rooms_boilers_page.dart | 7 ++-- .../boilers/settings_page_of_boilers.dart | 12 ++++--- .../boilers/smart_boiler_widget.dart | 3 +- ...itical_boilers_failure_display_widget.dart | 7 ++-- .../error_boilers_device_card_widget.dart | 7 ++-- .../boilers/widgets/room_boilers.dart | 3 +- .../widgets/room_boilers_toggles_block.dart | 3 +- .../boilers/widgets/rooms_boilers_widget.dart | 7 ++-- .../lights_in_the_room_page.dart | 2 +- .../lights_in_the_room_widget.dart | 3 +- .../lights/rooms_lights_page.dart | 7 ++-- .../lights/settings_page_of_lights.dart | 12 ++++--- .../lights/smart_lighte_widget.dart | 3 +- ...critical_light_failure_display_widget.dart | 7 ++-- .../error_lights_device_card_widget.dart | 7 ++-- .../lights_widgets/dimmable_light_widget.dart | 7 ++-- .../rgb_light_widgets/light_color_mods.dart | 14 ++++---- .../rgb_light_widgets/rgbw_light_widget.dart | 7 ++-- .../lights/widgets/room_lights.dart | 3 +- .../widgets/room_lights_toggles_block.dart | 3 +- .../lights/widgets/rooms_lights_widget.dart | 7 ++-- .../printers/printer_widget.dart | 5 +-- .../printers_in_the_room_page.dart | 2 +- .../printers_in_the_room_widget.dart | 3 +- .../printers/rooms_printers_page.dart | 7 ++-- .../printers/settings_page_of_printers.dart | 12 ++++--- ...tical_printers_failure_display_widget.dart | 7 ++-- .../error_printers_device_card_widget.dart | 7 ++-- .../printers/widgets/printer_widget.dart | 7 ++-- .../printers/widgets/room_printers.dart | 3 +- .../widgets/room_printers_toggles_block.dart | 3 +- .../widgets/rooms_printers_widget.dart | 7 ++-- .../rooms_smart_computers_page.dart | 7 ++-- .../settings_page_of_smart_computers.dart | 12 ++++--- .../smart_computer_widget.dart | 5 +-- .../smart_computers_in_the_room_page.dart | 2 +- .../smart_computers_in_the_room_widget.dart | 3 +- ...mart_computers_failure_display_widget.dart | 7 ++-- ...or_smart_computers_device_card_widget.dart | 7 ++-- .../widgets/room_smart_computers.dart | 3 +- .../room_smart_computers_toggles_block.dart | 3 +- .../widgets/rooms_smart_computers_widget.dart | 7 ++-- .../widgets/smart_computer_widget.dart | 14 ++++---- .../smart_plugs/rooms_smart_plugs_page.dart | 4 +-- .../settings_page_of_smart_plug.dart | 12 ++++--- .../smart_plugs/smart_plug_widget.dart | 3 +- .../smart_plugs_in_the_room_page.dart | 2 +- .../smart_plugs_in_the_room_widget.dart | 3 +- ...al_smart_plugs_failure_display_widget.dart | 7 ++-- .../error_smart_plugs_device_card_widget.dart | 7 ++-- .../smart_plugs/widgets/room_smart_plugs.dart | 3 +- .../room_smart_plugs_toggles_block.dart | 3 +- .../widgets/rooms_smart_plugs_widget.dart | 7 ++-- .../smart_tv/rooms_smart_tvs_page.dart | 7 ++-- .../smart_tv/settings_page_of_smart_tvs.dart | 24 ++++++------- .../smart_tv/smart_tv_widget.dart | 5 +-- .../smart_computers_in_the_room_page.dart | 2 +- .../smart_computers_in_the_room_widget.dart | 3 +- ...ical_smart_tvs_failure_display_widget.dart | 7 ++-- .../error_smart_tvs_device_card_widget.dart | 7 ++-- .../smart_tv/widgets/open_url_widget.dart | 5 +-- .../smart_tv/widgets/room_smart_tvs.dart | 3 +- .../widgets/room_smart_tvs_toggles_block.dart | 3 +- .../widgets/rooms_smart_tvs_widget.dart | 7 ++-- .../smart_tv/widgets/smart_tv_widget.dart | 34 ++++++++----------- .../switches/rooms_switches_page.dart | 5 ++- .../switches/settings_page_of_switches.dart | 12 ++++--- .../switches/smart_switch_widget.dart | 3 +- .../switches_in_the_room_page.dart | 2 +- .../switches_in_the_room_widget.dart | 3 +- ...tical_switches_failure_display_widget.dart | 7 ++-- .../error_switches_device_card_widget.dart | 7 ++-- .../switches/widgets/room_switches.dart | 3 +- .../widgets/room_switches_toggles_block.dart | 3 +- .../widgets/rooms_switches_widget.dart | 7 ++-- .../bottom_navigation_bar_home_page.dart | 9 +++-- .../pages/home_page/home_page.dart | 3 +- .../left_navigation_drawer_home_page.dart | 15 ++++---- .../pages/home_page/rooms_manager_widget.dart | 3 +- .../add_bindings/add_bindings_page.dart | 7 ++-- .../tabs/bindings_tab/bindings_page.dart | 9 ++--- .../tabs/history_tab/history_tab.dart | 8 ++--- .../history_tab/settings_page_of_history.dart | 6 ++-- .../scenes_in_folders_tab.dart | 6 ++-- .../widgets/scenes_in_folders_l.dart | 11 +++--- .../blinds_in_the_room.dart | 9 ++--- .../boilers_in_the_room.dart | 7 ++-- .../lights_in_the_room_block.dart | 19 +++++------ .../printers_in_the_room_block.dart | 7 ++-- .../security_cameras_in_the_room_block.dart | 7 ++-- .../smart_computers_in_the_room_block.dart | 7 ++-- .../smart_plug_in_the_room_block.dart | 19 +++++------ .../smart_tv_in_the_room.dart | 7 ++-- .../switches_in_the_room_block.dart | 19 +++++------ .../rooms_widgets/rom_widget.dart | 18 +++++----- .../rooms_widgets/rooms_list_view_widget.dart | 3 +- .../settings_page_of_smart_devices.dart | 3 +- .../smart_devices_by_rooms.dart | 22 ++++++------ .../smart_devices_widgets.dart | 6 ++-- .../introduction_screen_body.dart | 11 +++--- .../introduction_screen_body_about_page.dart | 3 +- ...introduction_screen_body_welcome_page.dart | 3 +- .../join_home_by_id/join_home_by_id_page.dart | 3 +- .../widgets/join_home_by_id_widget.dart | 15 ++++---- .../pages/manage_users/manage_users_page.dart | 3 +- .../widgets/error_user_card_widget.dart | 7 ++-- .../widgets/manage_users_widget.dart | 14 ++++---- .../widgets/user_card_widget.dart | 3 +- .../pages/plus_button/plus_button.dart | 3 +- .../widgets/plus_button_wighet.dart | 25 +++++++------- .../pages/remote_pipes/remote_pipes_page.dart | 3 +- .../error_remote_pipes_card_widget.dart | 7 ++-- .../widgets/manage_remote_pipes_widget.dart | 5 +-- .../widgets/remote_pipes_card_widget.dart | 3 +- .../pages/scenes/scenes_page.dart | 10 +++--- .../scenes/widgets/folder_of_scenes.dart | 15 ++++---- .../pages/scenes/widgets/scene_widget.dart | 11 +++--- .../shared_widgets/add_new_devie_widget.dart | 11 +++--- .../smart_device_type_and_toggle_bar.dart | 7 ++-- .../shared_widgets/top_navigation_bar.dart | 7 ++-- .../pages/sign_in_page/sign_in_page.dart | 3 +- .../widgets/sign_in_form_widget.dart | 9 ++--- .../software_info/software_info_page.dart | 3 +- .../error_software_info_card_widget.dart | 7 ++-- .../widgets/software_info_card_widget.dart | 3 +- .../widgets/software_info_widget.dart | 31 +++++++++-------- .../pages/splash/splash_page.dart | 3 +- .../where_to_login_page_minimal_page.dart | 11 +++--- .../widgets/error_home_card_widget.dart | 7 ++-- .../widgets/home_card_widget.dart | 13 +++---- .../widgets/user_homes_list_widget.dart | 12 +++---- .../where_to_login_page_offline.dart | 9 ++--- 200 files changed, 897 insertions(+), 732 deletions(-) create mode 100644 lib/presentation/atoms/atoms.dart create mode 100644 lib/presentation/atoms/image_atom.dart create mode 100644 lib/presentation/atoms/text_atom.dart rename lib/presentation/{atoms/empty => molecules/molecules.dart} (100%) delete mode 100644 lib/presentation/organisms/empty rename lib/presentation/{molecules/empty => organisms/organisms.dart} (100%) diff --git a/lib/application/auth/auth_bloc.dart b/lib/application/auth/auth_bloc.dart index 7e107c5fa..319a786c7 100644 --- a/lib/application/auth/auth_bloc.dart +++ b/lib/application/auth/auth_bloc.dart @@ -1,5 +1,4 @@ import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -13,7 +12,6 @@ class AuthBloc extends Bloc { AuthBloc() : super(const AuthState.initial()) { on(_initialized); on(_authCheckRequested); - on(_signedOut); } Future _initialized( @@ -42,12 +40,4 @@ class AuthBloc extends Bloc { // (_) => const AuthState.authenticated(), // ); } - - Future _signedOut( - SignedOut event, - Emitter emit, - ) async { - await IAuthFacade.instance.signOut(); - emit(const AuthState.unauthenticated()); - } } diff --git a/lib/application/auth/auth_event.dart b/lib/application/auth/auth_event.dart index 235728979..80b8398e2 100644 --- a/lib/application/auth/auth_event.dart +++ b/lib/application/auth/auth_event.dart @@ -5,6 +5,4 @@ class AuthEvent with _$AuthEvent { const factory AuthEvent.initialized() = Initialized; const factory AuthEvent.authCheckRequested() = AuthCheckRequested; - - const factory AuthEvent.signedOut() = SignedOut; } diff --git a/lib/presentation/atoms/atoms.dart b/lib/presentation/atoms/atoms.dart new file mode 100644 index 000000000..68b7930f4 --- /dev/null +++ b/lib/presentation/atoms/atoms.dart @@ -0,0 +1,2 @@ +export 'image_atom.dart'; +export 'text_atom.dart'; diff --git a/lib/presentation/atoms/image_atom.dart b/lib/presentation/atoms/image_atom.dart new file mode 100644 index 000000000..00466d77f --- /dev/null +++ b/lib/presentation/atoms/image_atom.dart @@ -0,0 +1,20 @@ +import 'package:flutter/cupertino.dart'; + +class ImageAtom extends StatelessWidget { + const ImageAtom(this.name, {this.fit, this.width, this.height}); + + final String name; + final BoxFit? fit; + final double? width; + final double? height; + + @override + Widget build(BuildContext context) { + return Image.asset( + name, + fit: fit, + width: width, + height: height, + ); + } +} diff --git a/lib/presentation/atoms/text_atom.dart b/lib/presentation/atoms/text_atom.dart new file mode 100644 index 000000000..33ed51aa9 --- /dev/null +++ b/lib/presentation/atoms/text_atom.dart @@ -0,0 +1,34 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; + +class TextAtom extends StatelessWidget { + const TextAtom( + this.text, { + super.key, + this.style = const TextStyle(), + this.textAlign, + this.overflow, + this.maxLines, + this.translationArgs, + this.translate = true, + }); + + final String text; + final TextStyle? style; + final TextAlign? textAlign; + final TextOverflow? overflow; + final int? maxLines; + final List? translationArgs; + final bool translate; + + @override + Widget build(BuildContext context) { + return Text( + translate && text.isNotEmpty ? text.tr(args: translationArgs) : text, + style: style, + maxLines: maxLines, + overflow: overflow, + textAlign: textAlign, + ); + } +} diff --git a/lib/presentation/core/devices_cards/blinds_card.dart b/lib/presentation/core/devices_cards/blinds_card.dart index 837436c20..1ebba6df9 100644 --- a/lib/presentation/core/devices_cards/blinds_card.dart +++ b/lib/presentation/core/devices_cards/blinds_card.dart @@ -1,5 +1,6 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class BlindsCard extends StatelessWidget { @@ -28,7 +29,7 @@ class BlindsCard extends StatelessWidget { return Container( margin: const EdgeInsets.only(top: 30), - child: const Text( + child: const TextAtom( 'Blinds action is not yet supported when adding new blinds', ), ); diff --git a/lib/presentation/core/theme_data.dart b/lib/presentation/core/theme_data.dart index 3d5f6df2c..046338d8e 100644 --- a/lib/presentation/core/theme_data.dart +++ b/lib/presentation/core/theme_data.dart @@ -38,8 +38,8 @@ class GradientColors { ]; } -class BacgroundGradient { - static LinearGradient getBacground(BuildContext context) { +class BackgroundGradient { + static LinearGradient getBackground(BuildContext context) { return LinearGradient( // Where the linear gradient begins and ends begin: Alignment.topRight, diff --git a/lib/presentation/atoms/empty b/lib/presentation/molecules/molecules.dart similarity index 100% rename from lib/presentation/atoms/empty rename to lib/presentation/molecules/molecules.dart diff --git a/lib/presentation/organisms/empty b/lib/presentation/organisms/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/presentation/molecules/empty b/lib/presentation/organisms/organisms.dart similarity index 100% rename from lib/presentation/molecules/empty rename to lib/presentation/organisms/organisms.dart diff --git a/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart b/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart index 484f1b387..cddf40205 100644 --- a/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart +++ b/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_new_action/add_new_action_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/application/add_new_action/add_new_action_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -26,7 +27,7 @@ class ActionChooseInformation extends StatelessWidget { ), const Row( children: [ - Text( + TextAtom( 'Choose Action', style: TextStyle(fontSize: 27), ), @@ -36,7 +37,7 @@ class ActionChooseInformation extends StatelessWidget { dropdownColor: Colors.black, style: const TextStyle(color: Colors.white), icon: const Icon(Icons.arrow_drop_down), - hint: Text( + hint: TextAtom( state.allDevicesWithNewAction.isNotEmpty ? state.allDevicesWithNewAction[0].key.cbjEntityName .getOrCrash()! @@ -55,7 +56,7 @@ class ActionChooseInformation extends StatelessWidget { items: state.allDevices.map>((e) { return DropdownMenuItem( value: e.uniqueId.getOrCrash(), - child: Text(e.cbjEntityName.getOrCrash()!), + child: TextAtom(e.cbjEntityName.getOrCrash()!), ); }).toList(), ), @@ -66,7 +67,7 @@ class ActionChooseInformation extends StatelessWidget { dropdownColor: Colors.black, style: const TextStyle(color: Colors.white), icon: const Icon(Icons.arrow_drop_down), - hint: Text( + hint: TextAtom( state.propertyName != '' ? state.propertyName : 'Property to change', @@ -87,13 +88,13 @@ class ActionChooseInformation extends StatelessWidget { .map>((e) { return DropdownMenuItem( value: e, - child: Text(e), + child: TextAtom(e), ); }).toList() : >[ const DropdownMenuItem( value: 'Choose device first', - child: Text('Choose device first'), + child: TextAtom('Choose device first'), ), ], ), @@ -104,7 +105,7 @@ class ActionChooseInformation extends StatelessWidget { dropdownColor: Colors.black, style: const TextStyle(color: Colors.white), icon: const Icon(Icons.arrow_drop_down), - hint: Text( + hint: TextAtom( state.actionsName != '' ? state.actionsName : 'Choose Action', @@ -128,13 +129,13 @@ class ActionChooseInformation extends StatelessWidget { .map>((e) { return DropdownMenuItem( value: e, - child: Text(e), + child: TextAtom(e), ); }).toList() : >[ const DropdownMenuItem( value: 'Choose property first', - child: Text('Choose property first'), + child: TextAtom('Choose property first'), ), ], ), @@ -163,7 +164,7 @@ class ActionChooseInformation extends StatelessWidget { state.allDevicesWithNewAction, ); }, - child: const Text( + child: const TextAtom( 'Done', style: TextStyle(fontSize: 20), ), diff --git a/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart b/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart index c5eb4baf0..f5c16a762 100644 --- a/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart @@ -1,8 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/add_new_binding/add_new_binding_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/application/add_new_binding/add_new_binding_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_bindings/widgets/binding_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -16,7 +17,7 @@ class AddBindingWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - initial: (_) => const Text('Initial'), + initial: (_) => const TextAtom('Initial'), loadPageState: (loadPageState) { return Container( margin: const EdgeInsets.symmetric(horizontal: 20), @@ -74,7 +75,7 @@ class AddBindingWidget extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add device action', style: TextStyle( color: Colors.blueGrey, @@ -102,7 +103,7 @@ class AddBindingWidget extends StatelessWidget { }, ), BottomSheetAction( - title: Text( + title: TextAtom( 'Add service action', style: TextStyle( color: Colors.green.shade600, @@ -125,7 +126,7 @@ class AddBindingWidget extends StatelessWidget { }, ), BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add time based action', style: TextStyle( color: Colors.blue, @@ -150,7 +151,7 @@ class AddBindingWidget extends StatelessWidget { ], ); }, - child: const Text('+ Add action'), + child: const TextAtom('+ Add action'), ), ), const SizedBox(height: 10), @@ -175,7 +176,7 @@ class AddBindingWidget extends StatelessWidget { const AddNewBindingEvent.sendBindingToHub(), ); }, - child: const Text('Add Binding'), + child: const TextAtom('Add Binding'), ), ), ], @@ -183,7 +184,7 @@ class AddBindingWidget extends StatelessWidget { ); }, loadInProgress: (loadInProgress) { - return const Text('loadInProgress'); + return const TextAtom('loadInProgress'); }, ); }, diff --git a/lib/presentation/pages/add_new_automation_process/add_routine/pick_repeat_time/pick_repeat_time_page.dart b/lib/presentation/pages/add_new_automation_process/add_routine/pick_repeat_time/pick_repeat_time_page.dart index ff2c9cd9d..e69bd9cb6 100644 --- a/lib/presentation/pages/add_new_automation_process/add_routine/pick_repeat_time/pick_repeat_time_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_routine/pick_repeat_time/pick_repeat_time_page.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/routine/value_objects_routine_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:day_night_time_picker/day_night_time_picker.dart'; @@ -59,7 +60,7 @@ class PickRepeatTimePage extends StatelessWidget { const SizedBox( height: 30, ), - const Text( + const TextAtom( 'Pick days and hour for the Routine to Repeat', style: TextStyle( color: Colors.black, @@ -136,14 +137,14 @@ class PickRepeatTimePage extends StatelessWidget { showDialog( context: context, builder: (_) => const AlertDialog( - title: Text( + title: TextAtom( 'Please choose days to repeat as well as time', ), ), ); } }, - child: const Text( + child: const TextAtom( 'Next', style: TextStyle(color: Colors.black), ), diff --git a/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart b/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart index 58c54c68d..721511f30 100644 --- a/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart @@ -1,8 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_routine/widgets/routine_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -16,7 +17,7 @@ class AddRoutineWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - initial: (_) => const Text('Initial'), + initial: (_) => const TextAtom('Initial'), loadPageState: (loadPageState) { return Container( margin: const EdgeInsets.symmetric(horizontal: 20), @@ -74,7 +75,7 @@ class AddRoutineWidget extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add device action', style: TextStyle( color: Colors.blueGrey, @@ -102,7 +103,7 @@ class AddRoutineWidget extends StatelessWidget { }, ), BottomSheetAction( - title: Text( + title: TextAtom( 'Add service action', style: TextStyle( color: Colors.green.shade600, @@ -125,7 +126,7 @@ class AddRoutineWidget extends StatelessWidget { }, ), BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add time based action', style: TextStyle( color: Colors.blue, @@ -150,7 +151,7 @@ class AddRoutineWidget extends StatelessWidget { ], ); }, - child: const Text('+ Add action'), + child: const TextAtom('+ Add action'), ), ), const SizedBox(height: 10), @@ -175,7 +176,7 @@ class AddRoutineWidget extends StatelessWidget { const AddNewRoutineEvent.sendRoutineToHub(), ); }, - child: const Text('Add Routine'), + child: const TextAtom('Add Routine'), ), ), ], @@ -183,10 +184,10 @@ class AddRoutineWidget extends StatelessWidget { ); }, loadInProgress: (loadInProgress) { - return const Text('load In Progress'); + return const TextAtom('load In Progress'); }, addNewRoutineFailure: (AddNewRoutineFailure value) { - return const Text('Failure while adding new routine'); + return const TextAtom('Failure while adding new routine'); }, ); }, diff --git a/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart b/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart index 41d45c6e9..94568b13c 100644 --- a/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart @@ -1,8 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/add_new_scene/add_new_scene_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/application/add_new_scene/add_new_scene_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_scene/widgets/scene_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -16,7 +17,7 @@ class AddSceneWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - initial: (_) => const Text('Initial'), + initial: (_) => const TextAtom('Initial'), loadPageState: (loadPageState) { return Container( margin: const EdgeInsets.symmetric(horizontal: 20), @@ -74,7 +75,7 @@ class AddSceneWidget extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add device action', style: TextStyle( color: Colors.blueGrey, @@ -102,7 +103,7 @@ class AddSceneWidget extends StatelessWidget { }, ), BottomSheetAction( - title: Text( + title: TextAtom( 'Add service action', style: TextStyle( color: Colors.green.shade600, @@ -125,7 +126,7 @@ class AddSceneWidget extends StatelessWidget { }, ), BottomSheetAction( - title: const Text( + title: const TextAtom( 'Add time based action', style: TextStyle( color: Colors.blue, @@ -150,7 +151,7 @@ class AddSceneWidget extends StatelessWidget { ], ); }, - child: const Text('+ Add action'), + child: const TextAtom('+ Add action'), ), ), const SizedBox(height: 10), @@ -175,7 +176,7 @@ class AddSceneWidget extends StatelessWidget { const AddNewSceneEvent.sendSceneToHub(), ); }, - child: const Text('Add Scene'), + child: const TextAtom('Add Scene'), ), ), ], @@ -183,7 +184,7 @@ class AddSceneWidget extends StatelessWidget { ); }, loadInProgress: (loadInProgress) { - return const Text('loadInProgress'); + return const TextAtom('loadInProgress'); }, ); }, diff --git a/lib/presentation/pages/add_new_automation_process/choose_automation_type_to_add/choose_automation_type_to_add_page.dart b/lib/presentation/pages/add_new_automation_process/choose_automation_type_to_add/choose_automation_type_to_add_page.dart index a52348f60..0771418f0 100644 --- a/lib/presentation/pages/add_new_automation_process/choose_automation_type_to_add/choose_automation_type_to_add_page.dart +++ b/lib/presentation/pages/add_new_automation_process/choose_automation_type_to_add/choose_automation_type_to_add_page.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:auto_size_text/auto_size_text.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; @@ -41,7 +42,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { const SizedBox( height: 20, ), - const Text( + const TextAtom( 'Do several things at once or start actions' ' automatically by adding a trigger.', style: TextStyle( @@ -51,7 +52,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { const SizedBox( height: 13, ), - const Text( + const TextAtom( 'Please choose your automation trigger', style: TextStyle( color: Colors.black, @@ -79,7 +80,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { children: [ Row( children: [ - Text( + TextAtom( 'Scenes - ', style: TextStyle( color: Colors.black, @@ -95,14 +96,14 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { ), ], ), - Text( + TextAtom( 'Combining a number of actions in a big button.', style: TextStyle( color: Colors.black, fontSize: 13, ), ), - Text( + TextAtom( 'Example:\n"Arriving Home" button that will turn on some lights and turn up all the blinds when you click on it.', style: TextStyle( color: Colors.black, @@ -128,7 +129,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { // showDialog( // context: context, // builder: (_) => const AlertDialog( - // title: Text( + // title: TextAtom( // 'Not supported yet', // ), // ), @@ -139,7 +140,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { children: [ Row( children: [ - Text( + TextAtom( 'Routines - ', style: TextStyle( color: Colors.black, @@ -155,14 +156,14 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { ), ], ), - Text( + TextAtom( 'Like alarm clock but for triggering actions.', style: TextStyle( color: Colors.black, fontSize: 13, ), ), - Text( + TextAtom( 'Example:\nTurn on the thermostat for an hour and open all blinds each day at 7:00am.', style: TextStyle( color: Colors.black, @@ -188,7 +189,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { showDialog( context: context, builder: (_) => const AlertDialog( - title: Text( + title: TextAtom( 'Not supported yet', ), ), @@ -202,7 +203,7 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { children: [ Row( children: [ - Text( + TextAtom( 'Bindings - ', style: TextStyle( color: Colors.black, @@ -218,14 +219,14 @@ class ChooseAutomationTypeToAddPage extends StatelessWidget { ), ], ), - Text( + TextAtom( 'Trigger actions whenever an external action occurs.', style: TextStyle( color: Colors.black, fontSize: 13, ), ), - Text( + TextAtom( 'Example:\nIf the home door got opened from 3:00am - 6:00am trigger anti-thief alarm system.', style: TextStyle( color: Colors.black, diff --git a/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart b/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart index 4e9a5cf03..2866d3d53 100644 --- a/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart +++ b/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -85,7 +86,7 @@ class _AddNewCBJDevices extends State { height: 50, ), - const Text( + const TextAtom( "Can't find any devices", style: TextStyle( fontSize: 15.0, diff --git a/lib/presentation/pages/add_new_devices/smart_device_to_configure.dart b/lib/presentation/pages/add_new_devices/smart_device_to_configure.dart index 8af6cfec5..ca481fa8c 100644 --- a/lib/presentation/pages/add_new_devices/smart_device_to_configure.dart +++ b/lib/presentation/pages/add_new_devices/smart_device_to_configure.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/smart_device_type_and_toggle_bar.dart'; import 'package:flutter/material.dart'; @@ -15,7 +16,7 @@ class SmartDeviceToConfigure extends StatelessWidget { child: Column( children: [ SmartDeviceTypeAndToggleBar(smartDeviceObject), - Text( + TextAtom( 'Device Name: ${smartDeviceObject.cbjEntityName.getOrCrash()}', style: const TextStyle(fontSize: 21), ), @@ -29,7 +30,7 @@ class SmartDeviceToConfigure extends StatelessWidget { ), ), onPressed: () {}, - child: Text( + child: TextAtom( 'Edit device', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, 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 7ec9f112e..c34a51018 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 @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/vendors/vendors_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; @@ -38,7 +39,7 @@ class ChooseDeviceVendorToAddPage extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 40), alignment: Alignment.centerLeft, - child: Text( + child: TextAtom( 'Vendors:', style: TextStyle(color: HexColor('#6599CA'), fontSize: 20), ), @@ -52,7 +53,7 @@ class ChooseDeviceVendorToAddPage extends StatelessWidget { ), const SizedBox( height: 50, - child: Text(''), + child: TextAtom(''), ), ], ), 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 26f90580c..2787a4789 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 @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -86,7 +87,7 @@ class VendorWidget extends StatelessWidget { const SizedBox( width: 10, ), - Text( + TextAtom( vendor.name.getOrCrash(), style: const TextStyle( color: Colors.black, diff --git a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart index 5468c4dfd..90f92e1dc 100644 --- a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart +++ b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/application/vendors/vendors_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -6,12 +7,10 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class VendorsList extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - return BlocBuilder( builder: (context, state) { return state.map( - (value) => const Text('sd'), + (value) => const TextAtom('sd'), loading: (_) => const Center( child: CircularProgressIndicator(), ), @@ -32,7 +31,7 @@ class VendorsList extends StatelessWidget { ); }, error: (_) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart index ba9b54e11..186c50d23 100644 --- a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart @@ -2,6 +2,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -32,7 +33,7 @@ class ComputerConnectionCheckWidget extends StatelessWidget { child: SizedBox( height: 80, width: 250, - child: Text( + child: TextAtom( 'Please reconnect back to you home WiFi', style: TextStyle(fontSize: 20), ), @@ -58,7 +59,7 @@ class ComputerConnectionCheckWidget extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'Connecting computer to WiFi', style: TextStyle( fontSize: 25, @@ -82,7 +83,7 @@ class ComputerConnectionCheckWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, borderColor: Colors.red.withOpacity(0.9), borderWidth: 4.0, - center: const Text( + center: const TextAtom( 'Loading...', style: TextStyle(color: Colors.black), ), @@ -92,7 +93,7 @@ class ComputerConnectionCheckWidget extends StatelessWidget { const SizedBox( height: 20, ), - Text( + TextAtom( 'Searching for CyBear Jinni Hub in your WiFi network', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -113,14 +114,14 @@ class ComputerConnectionCheckWidget extends StatelessWidget { linearProgressIndicator: const LinearProgressIndicator(), ).show(context); - return const Text('completeSuccess'); + return const TextAtom('completeSuccess'); }, errorInProcess: (ErrorInProcess value) { return Expanded( child: Center( child: Column( children: [ - const Text( + const TextAtom( 'Error finding CyBear Jinni Hub in your current' ' network.\n' 'Please restart connecting Hub to WiFi process.', @@ -129,7 +130,7 @@ class ComputerConnectionCheckWidget extends StatelessWidget { onPressed: () { context.router.replace(const ConnectToHubRoute()); }, - child: const Text('Go Back'), + child: const TextAtom('Go Back'), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index 3e6ec63af..0009a9042 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -1,10 +1,11 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/blinds_card.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/light_card.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; @@ -56,7 +57,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { margin: const EdgeInsets.symmetric(horizontal: 40), child: Row( children: [ - Text('Type: ${device.entityTypes.getOrCrash()}'), + TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Expanded( child: Center( child: BlocProvider( @@ -74,7 +75,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { margin: const EdgeInsets.symmetric(horizontal: 40), child: Row( children: [ - Text('Type: ${device.entityTypes.getOrCrash()}'), + TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Expanded( child: Center( child: BlocProvider( @@ -90,7 +91,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { EntityTypes.blinds.toString()) Column( children: [ - Text('Type: ${device.entityTypes.getOrCrash()}'), + TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Center( child: BlocProvider( create: (context) => getIt(), @@ -146,7 +147,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { children: [ Expanded( child: Center( - child: Text( + child: TextAtom( 'Type ${device.entityTypes.getOrCrash()} is not supported yet', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -183,7 +184,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { state = const ConfigureNewCbjCompState.actionInProgress(0); - return Text( + return TextAtom( 'Configure devices', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -204,7 +205,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'Connecting computer to WiFi', style: TextStyle( fontSize: 25, @@ -228,7 +229,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, borderColor: Colors.red.withOpacity(0.9), borderWidth: 4.0, - center: const Text( + center: const TextAtom( 'Loading...', style: TextStyle(color: Colors.black), ), @@ -238,7 +239,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { const SizedBox( height: 20, ), - Text( + TextAtom( 'Please wait as we are setting your new computer', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -258,7 +259,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { ); }, errorInProcess: (value) { - return Text( + return TextAtom( 'Error in the process.', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -271,7 +272,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { cbjCompEntity: cbjCompEntity, ), ); - return Text( + return TextAtom( 'Computer have been configured.', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart index 5eb68a380..23c024c60 100644 --- a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/manage_wifi/manage_wifi_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; @@ -58,7 +59,7 @@ class ConnectToHomeWifiPage extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'Connect Hub To Home WiFi', style: TextStyle( fontSize: 25, diff --git a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart index 782b7b0ce..552b58dbb 100644 --- a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/manage_wifi/manage_wifi_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -14,7 +15,7 @@ class ConnectToHomeWiFiWidget extends StatelessWidget { children: [ state.map( initial: (value) { - return const Text('Initial'); + return const TextAtom('Initial'); }, loading: (_) { return const CircularProgressIndicator( @@ -24,17 +25,17 @@ class ConnectToHomeWiFiWidget extends StatelessWidget { }, loaded: (l) { context.router.replace(const OpenAccessPointRoute()); - return const Text('Loaded'); + return const TextAtom('Loaded'); }, error: (e) { - return const Text('Failure'); + return const TextAtom('Failure'); }, wifiIsEnabled: (WifiIsEnabled wifiIsEnabled) { return Column( children: [ Container( margin: const EdgeInsets.symmetric(horizontal: 50), - child: const Text( + child: const TextAtom( 'Smart Devices need your home WiFi name and ' 'password in order to connect.', style: TextStyle(fontSize: 17), @@ -117,7 +118,7 @@ class ConnectToHomeWiFiWidget extends StatelessWidget { .read() .add(ManageWifiEvent.connectToWiFi()); }, - child: Text( + child: TextAtom( 'Connect to WiFi', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -128,7 +129,7 @@ class ConnectToHomeWiFiWidget extends StatelessWidget { ); }, wifiIsDisabled: (WifiIsDisabled value) { - return const Text('WiFi is disabled'); + return const TextAtom('WiFi is disabled'); }, ), // TextButton( @@ -140,7 +141,7 @@ class ConnectToHomeWiFiWidget extends StatelessWidget { // onPressed: () { // context.router.replace(const OpenAccessPointRoute()); // }, - // child: const Text('Next'), + // child: const TextAtom('Next'), // ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart index eac241f47..2dd2e7540 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/manage_access_point/manage_access_point_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; @@ -58,7 +59,7 @@ class OpenAccessPointPage extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'Open Access Point', style: TextStyle( fontSize: 25, diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart index 0035f797b..3459be8aa 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:clipboard/clipboard.dart'; import 'package:cybear_jinni/application/manage_access_point/manage_access_point_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -9,8 +10,6 @@ import 'package:fluttertoast/fluttertoast.dart'; class OpenAccessPointWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - return BlocBuilder( builder: (context, state) { return SingleChildScrollView( @@ -29,7 +28,7 @@ class OpenAccessPointWidget extends StatelessWidget { .read() .add(ManageAccessPointEvent.initialized()); }, - child: const Text('Create Access Pint'), + child: const TextAtom('Create Access Pint'), ); }, loading: (_) { @@ -41,17 +40,17 @@ class OpenAccessPointWidget extends StatelessWidget { loaded: (l) { // ExtendedNavigator.of(context) // .push(Routes.openAccessPointPage); - return const Text('Loaded'); + return const TextAtom('Loaded'); }, error: (e) { - return const Text('Failure'); + return const TextAtom('Failure'); }, iOSDevice: (IOSDevice value) { return Column( children: [ Container( margin: const EdgeInsets.symmetric(horizontal: 50), - child: const Text( + child: const TextAtom( 'Please Open Access point with the following ' 'credentials in the OS Settings.', style: TextStyle(fontSize: 17), @@ -88,11 +87,11 @@ class OpenAccessPointWidget extends StatelessWidget { }, child: const Column( children: [ - Text( + TextAtom( 'Hotspot name:', style: TextStyle(color: Colors.white60), ), - Text( + TextAtom( 'CyBear Jinni', style: TextStyle( fontWeight: FontWeight.bold, @@ -136,11 +135,11 @@ class OpenAccessPointWidget extends StatelessWidget { }, child: const Column( children: [ - Text( + TextAtom( 'Hotspot password:', style: TextStyle(color: Colors.white60), ), - Text( + TextAtom( 'CyBear Jinni', style: TextStyle( fontWeight: FontWeight.bold, @@ -164,19 +163,19 @@ class OpenAccessPointWidget extends StatelessWidget { }, cantDetermineAccessPointOpenOrNot: (CantDetermineAccessPointOpenOrNot value) { - return const Text('CantDetermineAccessPointOpenOrNot'); + return const TextAtom('CantDetermineAccessPointOpenOrNot'); }, accessPointIsNotOpen: (AccessPointIsNotOpen value) { - return const Text('AccessPointIsNotOpen'); + return const TextAtom('AccessPointIsNotOpen'); }, accessPointIsOpen: (AccessPointIsOpen value) { context.router.replace(const ScanForNewCBJCompsRoute()); - return const Text('AccessPointIsOpen'); + return const TextAtom('AccessPointIsOpen'); }, ), Container( margin: const EdgeInsets.symmetric(horizontal: 50), - child: const Text( + child: const TextAtom( "Currently we can't verify that you have opened Access pont.\n" 'Press next only after you have preformed the actions above!.', style: TextStyle(fontSize: 17), @@ -196,7 +195,7 @@ class OpenAccessPointWidget extends StatelessWidget { .read() .add(ManageAccessPointEvent.doesAccessPointOpen()); }, - child: const Text('Next'), + child: const TextAtom('Next'), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart index 0c0082831..cf1c2d804 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart @@ -1,9 +1,10 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -33,7 +34,7 @@ class CBJCompCard extends StatelessWidget { ), ), child: cbjCompEntity.cBJCompDevices!.getOrCrash().size < 1 - ? const Text('') + ? const TextAtom('') : ListView.builder( padding: EdgeInsets.zero, itemBuilder: (context, index) { @@ -44,7 +45,7 @@ class CBJCompCard extends StatelessWidget { return Center( child: BlocProvider( create: (context) => getIt(), - child: Text( + child: TextAtom( compEntity.cbjEntityName.getOrCrash()!, style: TextStyle( color: Theme.of(context) @@ -56,7 +57,7 @@ class CBJCompCard extends StatelessWidget { ), ); } else { - return Text( + return TextAtom( 'Type not supported ' '${compEntity.entityTypes.getOrCrash()} yet', style: TextStyle( @@ -82,7 +83,7 @@ class CBJCompCard extends StatelessWidget { ConfigureNewCbjCompRoute(cbjCompEntity: cbjCompEntity), ); }, - child: Text( + child: TextAtom( 'Set up computer', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart index e37519ca4..d69dfba62 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart @@ -1,9 +1,10 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -30,7 +31,7 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { color: Colors.yellowAccent.withOpacity(0.3), child: BlocProvider( create: (context) => getIt(), - child: Text( + child: TextAtom( 'Type: ${deviceEntity.entityTypes.getOrCrash()}', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -43,7 +44,7 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { typesList.add( ColoredBox( color: Colors.orange.withOpacity(0.3), - child: Text( + child: TextAtom( 'Type ${deviceEntity.entityTypes.getOrCrash()} is not supported', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -54,7 +55,7 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { } } if (typesList.isEmpty) { - typesList.add(const Text('Computer does not contain any devices')); + typesList.add(const TextAtom('Computer does not contain any devices')); } final Column deviceColumn = Column( @@ -96,25 +97,25 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { height: 30, ), state.map( - initial: (_) => Text( + initial: (_) => TextAtom( 'Initial', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - actionInProgress: (_) => Text( + actionInProgress: (_) => TextAtom( 'actionInProgress', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - deleteFailure: (_) => Text( + deleteFailure: (_) => TextAtom( 'deleteFailure', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - deleteSuccess: (_) => Text( + deleteSuccess: (_) => TextAtom( 'deleteSuccess', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -132,7 +133,7 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { ConfigureNewCbjCompRoute(cbjCompEntity: cbjCompEntity), ); }, - child: Text( + child: TextAtom( 'Set up computer', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart index 6fe72e755..e1d803ea4 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/cbj_comp/cbj_comp_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -14,14 +15,14 @@ class ScanForNewCBJCompsWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - initial: (_) => const Text('Initial'), + initial: (_) => const TextAtom('Initial'), loadInProgress: (value) { return Column( children: [ const SizedBox( height: 20, ), - Text( + TextAtom( 'Scanning For Devices', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -52,13 +53,13 @@ class ScanForNewCBJCompsWidget extends StatelessWidget { ); }, loadSuccessTemp: (state) { - return const Text('Load success temp'); + return const TextAtom('Load success temp'); }, loadFailure: (state) { - return const Text('Load Failure'); + return const TextAtom('Load Failure'); }, error: (state) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/add_new_room/add_new_room_page.dart b/lib/presentation/pages/add_new_room/add_new_room_page.dart index 5e721c89d..3faf1eb58 100644 --- a/lib/presentation/pages/add_new_room/add_new_room_page.dart +++ b/lib/presentation/pages/add_new_room/add_new_room_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_room/widgets/add_new_room_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -12,7 +13,7 @@ class AddNewRoomPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.purple, - title: const Text('Add New Area'), + title: const TextAtom('Add New Area'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart b/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart index 6df5d5d35..0a530cdba 100644 --- a/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart +++ b/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -67,7 +68,7 @@ class AddNewRoomForm extends StatelessWidget { ).tr(), cancelText: const Text('CANCEL').tr(), confirmText: const Text('OK').tr(), - title: const Text('Select').tr(), + title: const TextAtom('Select'), items: AreaPurposesTypes.values .map((AreaPurposesTypes areaPurposeType) { final String tempAreaName = areaPurposeType.name @@ -123,7 +124,7 @@ class AddNewRoomForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('ADD').tr(), + child: const TextAtom('ADD'), ), ), ], diff --git a/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart b/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart index e25f4ec97..ce08fc520 100644 --- a/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart +++ b/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/add_user_to_home/add_user_to_home_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,7 +12,7 @@ class AddUserToHomePage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Add user'), + title: const TextAtom('Add user'), ), backgroundColor: Colors.blueAccent.withOpacity(0.7), body: BlocProvider( diff --git a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart b/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart index 5516e4028..1a5c741a1 100644 --- a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart +++ b/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart @@ -1,5 +1,6 @@ import 'package:clipboard/clipboard.dart'; import 'package:cybear_jinni/application/add_user_to_home/add_user_to_home_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -12,7 +13,7 @@ class AddUserToHomeWidget extends StatelessWidget { return BlocConsumer( listener: (context, state) { state.map( - (value) => const Text('Initial'), + (value) => const TextAtom('Initial'), actionInProgress: (_) { return const CircularProgressIndicator( backgroundColor: Colors.cyan, @@ -20,10 +21,11 @@ class AddUserToHomeWidget extends StatelessWidget { ); }, addingUserSuccess: (s) { - return TextButton(onPressed: () {}, child: const Text('Success')); + return TextButton( + onPressed: () {}, child: const TextAtom('Success')); }, addingHomeFailure: (e) { - return const Text('Failure'); + return const TextAtom('Failure'); }, ); }, @@ -38,7 +40,7 @@ class AddUserToHomeWidget extends StatelessWidget { const SizedBox( width: 10, ), - const Text('Email'), + const TextAtom('Email'), const SizedBox( width: 30, ), @@ -82,7 +84,7 @@ class AddUserToHomeWidget extends StatelessWidget { AddUserToHomeEvent.addUserToHomeByEmail(userToAddEmail), ); }, - child: Text( + child: TextAtom( 'Add User', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -105,7 +107,7 @@ class AddUserToHomeWidget extends StatelessWidget { const SizedBox( height: 30, ), - Text( + TextAtom( 'User have been add successfully', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -118,7 +120,7 @@ class AddUserToHomeWidget extends StatelessWidget { const SizedBox( height: 30, ), - Text( + TextAtom( 'Copy home ID', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -149,8 +151,8 @@ class AddUserToHomeWidget extends StatelessWidget { }, child: Column( children: [ - const Text('Press to copy'), - Text( + const TextAtom('Press to copy'), + TextAtom( s.homeId, style: TextStyle( color: Theme.of(context) @@ -164,7 +166,7 @@ class AddUserToHomeWidget extends StatelessWidget { ], ), ), - Text( + TextAtom( 'Please give home id to the user, he needs it to' ' join the home.', style: TextStyle( @@ -177,7 +179,7 @@ class AddUserToHomeWidget extends StatelessWidget { ); }, addingHomeFailure: (e) { - return Text( + return TextAtom( 'Adding user Failed.\n' 'Did the user already created account with that email?', style: TextStyle( diff --git a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart index d14ee59d8..aff374e71 100644 --- a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; import 'package:cybear_jinni/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddEspHomeVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.black, - title: const Text('EspHome Sign In'), + title: const TextAtom('EspHome Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart index 2d7bf5daf..047060788 100644 --- a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart @@ -1,11 +1,11 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cybear_jinni/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -66,7 +66,7 @@ class EspHomeSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -123,7 +123,7 @@ class EspHomeSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart index 5980d4046..719fdbb22 100644 --- a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddEwelinkVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.blueAccent, - title: const Text('eWeLink Sign In'), + title: const TextAtom('eWeLink Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart index 7a797fb57..fbb5b5132 100644 --- a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart @@ -1,11 +1,11 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -64,7 +64,7 @@ class EwelinkSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -153,7 +153,7 @@ class EwelinkSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart index 7381f0e70..c77ffd01a 100644 --- a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddJinvooSmartVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.indigo, - title: const Text('Jinvoo Smart Sign In'), + title: const TextAtom('Jinvoo Smart Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart index 6b3e5d7cd..9c55c458c 100644 --- a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart @@ -1,12 +1,12 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -70,7 +70,7 @@ class JinvooSmartSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -158,7 +158,7 @@ class JinvooSmartSignInForm extends StatelessWidget { const SizedBox( height: 8, ), - const Text( + const TextAtom( 'Select Region:', style: TextStyle(color: Colors.black), ), @@ -169,7 +169,7 @@ class JinvooSmartSignInForm extends StatelessWidget { .tuyaLoginRegion .getOrCrash(), icon: const Icon(Icons.arrow_drop_down), - hint: const Text('Jinvoo Smart Region'), + hint: const TextAtom('Jinvoo Smart Region'), elevation: 16, underline: Container( height: 2, @@ -184,7 +184,7 @@ class JinvooSmartSignInForm extends StatelessWidget { ].map>((String value) { return DropdownMenuItem( value: value, - child: Text(value), + child: TextAtom(value), ); }).toList(), ), @@ -220,7 +220,7 @@ class JinvooSmartSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart index c89357e7d..50a464125 100644 --- a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddLifxVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepPurple, - title: const Text('Xiaomi Mi Sign In'), + title: const TextAtom('Xiaomi Mi Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart index 89bd31efd..8ee390511 100644 --- a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart @@ -1,11 +1,11 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -70,7 +70,7 @@ class LifxSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -129,7 +129,7 @@ class LifxSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], @@ -153,12 +153,12 @@ class LifxSignInForm extends StatelessWidget { onPressed: () { launchUrl(Uri.parse('https://cloud.lifx.com/')); }, - child: Text( + child: TextAtom( 'Get Lifx API key from Lifx website', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), + ), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart index d8e079463..0d4be6081 100644 --- a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddSmartLifeVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.lightBlueAccent, - title: const Text('Smart Life Sign In'), + title: const TextAtom('Smart Life Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart index f6e49098f..bac2799d9 100644 --- a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart @@ -1,12 +1,12 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -70,7 +70,7 @@ class SmartLifeSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -158,7 +158,7 @@ class SmartLifeSignInForm extends StatelessWidget { const SizedBox( height: 8, ), - const Text( + const TextAtom( 'Select Region:', style: TextStyle(color: Colors.black), ), @@ -169,7 +169,7 @@ class SmartLifeSignInForm extends StatelessWidget { .tuyaLoginRegion .getOrCrash(), icon: const Icon(Icons.arrow_drop_down), - hint: const Text('Smart Life Region'), + hint: const TextAtom('Smart Life Region'), elevation: 16, underline: Container( height: 2, @@ -184,7 +184,7 @@ class SmartLifeSignInForm extends StatelessWidget { ].map>((String value) { return DropdownMenuItem( value: value, - child: Text(value), + child: TextAtom(value), ); }).toList(), ), @@ -221,7 +221,7 @@ class SmartLifeSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart index 2aef8c6f1..df3dec964 100644 --- a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddTuyaVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepOrange, - title: const Text('Tuya Sign In'), + title: const TextAtom('Tuya Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart index c1dd7237c..b1158e8c7 100644 --- a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart @@ -1,12 +1,12 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -70,7 +70,7 @@ class TuyaSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -158,7 +158,7 @@ class TuyaSignInForm extends StatelessWidget { const SizedBox( height: 8, ), - const Text( + const TextAtom( 'Select Region:', style: TextStyle(color: Colors.black), ), @@ -169,7 +169,7 @@ class TuyaSignInForm extends StatelessWidget { .tuyaLoginRegion .getOrCrash(), icon: const Icon(Icons.arrow_drop_down), - hint: const Text('Tuna Region'), + hint: const TextAtom('Tuna Region'), elevation: 16, underline: Container( height: 2, @@ -184,7 +184,7 @@ class TuyaSignInForm extends StatelessWidget { ].map>((String value) { return DropdownMenuItem( value: value, - child: Text(value), + child: TextAtom(value), ); }).toList(), ), @@ -220,7 +220,7 @@ class TuyaSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), + child: const TextAtom('SIGN IN'), ), ), ], diff --git a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart index c1eff44cc..782f8f074 100644 --- a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart @@ -1,7 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -17,7 +18,7 @@ class AddXiaomiMiVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepOrange, - title: const Text('XiaomiMi Sign In'), + title: const TextAtom('XiaomiMi Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart index 1e80fc947..9fa1b2aaf 100644 --- a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart @@ -1,11 +1,11 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; +import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -64,7 +64,7 @@ class XiaomiMiSignInForm extends StatelessWidget { ), ), ), - // Image.asset('assets/cbj_logo.png'), + // ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -156,8 +156,7 @@ class XiaomiMiSignInForm extends StatelessWidget { ); Navigator.pop(context); }, - child: const Text('SIGN IN').tr(), - ), + child: const TextAtom('SIGN IN'), ), ), ], ), diff --git a/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart b/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart index c8f6c5cd3..40db232b3 100644 --- a/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart +++ b/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -25,7 +26,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text( + const TextAtom( 'Choose Area', style: TextStyle(fontSize: 27), ), @@ -33,7 +34,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { onPressed: () { context.router.push(const AddNewRoomRoute()); }, - child: const Text( + child: const TextAtom( 'Add New Area', style: TextStyle( fontSize: 16, @@ -48,7 +49,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { dropdownColor: Colors.black, style: const TextStyle(color: Colors.white), icon: const Icon(Icons.arrow_drop_down), - hint: Text( + hint: TextAtom( state.cbjEntityName.isValid() ? state.cbjEntityName.getOrCrash() : 'Choose Area', @@ -67,7 +68,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { // .map>((String value) { return DropdownMenuItem( value: e.uniqueId.getOrCrash(), - child: Text(e.cbjEntityName.getOrCrash()), + child: TextAtom(e.cbjEntityName.getOrCrash()), ); }).toList(), ), @@ -76,7 +77,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { ), const Row( children: [ - Text( + TextAtom( 'Choose Device', style: TextStyle(fontSize: 27), ), @@ -122,7 +123,7 @@ class ChangeRoomForDevicesWidget extends StatelessWidget { RoomSignInFormEvent.changeRoomDevices(context), ); }, - child: const Text( + child: const TextAtom( 'Done', style: TextStyle(fontSize: 20), ), diff --git a/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart b/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart index b90f888cd..f0e534400 100644 --- a/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart +++ b/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/hub_in_network/hub_in_network_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -47,7 +48,7 @@ class ConnectToHubPage extends StatelessWidget { ), Container( alignment: Alignment.center, - child: const Text( + child: const TextAtom( ' Connect to Hub', textAlign: TextAlign.center, style: TextStyle( @@ -81,7 +82,7 @@ class ConnectToHubPage extends StatelessWidget { width: 40, ), Flexible( - child: Text( + child: TextAtom( 'Search a CyBear Jinni Hub in your network', style: TextStyle( color: Colors.white, @@ -238,7 +239,7 @@ class ConnectToHubPage extends StatelessWidget { minimumSize: const Size(70, 30), backgroundColor: HexColor('#985dc7'), ), - child: const Text( + child: const TextAtom( 'More', style: TextStyle(color: Colors.white), ), diff --git a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart index 490ce01bb..f21a0268a 100644 --- a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart +++ b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/hub_in_network/hub_in_network_bloc.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -13,19 +14,19 @@ class CbjHubInNetworkWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - initial: (_) => const Text('Go'), + initial: (_) => const TextAtom('Go'), loadInProgress: (_) => const SizedBox( height: 70, width: 70, child: CircularProgressIndicator(), ), - loadSuccess: (_) => const Text('Found hub'), + loadSuccess: (_) => const TextAtom('Found hub'), loadSuccessSecurityCamera: (loadSuccessSecurityCamera value) { context.router.push( VideoStreamOutputContainerRoute(streamAddress: value.address), ); - return const Text('Found Smart Camera'); + return const TextAtom('Found Smart Camera'); }, loadFailure: (failure) { if (failure.hubFailure == @@ -33,7 +34,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( + const TextAtom( "Can't find a Hub in your network.", style: TextStyle(color: Colors.white), ), @@ -53,7 +54,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { const HubInNetworkEvent.searchHubInNetwork(), ); }, - child: const Text('Retry'), + child: const TextAtom('Retry'), ), const SizedBox( width: 40, @@ -72,7 +73,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { ), ); }, - child: const Text('Retry Manually'), + child: const TextAtom('Retry Manually'), ), ], ), @@ -80,7 +81,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { ); } else if (failure.hubFailure == const HubFailures.automaticHubSearchNotSupportedOnWeb()) { - return const Text( + return const TextAtom( 'Automatic search does not supported on the web.', ); } else if (failure.hubFailure == @@ -96,7 +97,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text("Unexpected error"), + const TextAtom("Unexpected error"), const SizedBox( height: 20, ), @@ -109,19 +110,19 @@ class CbjHubInNetworkWidget extends StatelessWidget { const HubInNetworkEvent.searchHubInNetwork(), ); }, - child: const Text('Retry'), + child: const TextAtom('Retry'), ), ], ); }, - lightError: (_) => const Text('Got Error'), + lightError: (_) => const TextAtom('Got Error'), tryIpManually: (TryIpManually tryIpManuallyValue) { String anyIpOnTheNetwork = tryIpManuallyValue.ipOnTheNetwork; return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( + const TextAtom( "Automatic search currently supported only on WiFi.\n" "Please enter manually any IP on the network or connect the device to WiFi and try again.", style: TextStyle( @@ -152,7 +153,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( + const TextAtom( 'Is Hub IP', style: TextStyle( fontSize: 17, @@ -179,7 +180,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { showDialog( context: context, builder: (_) => const AlertDialog( - title: Text( + title: TextAtom( 'Please insert valid IP before clicking the Search Button', ), ), @@ -193,7 +194,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { ), ); }, - child: const Text( + child: const TextAtom( 'Search', style: TextStyle(color: Colors.white), ), @@ -209,7 +210,7 @@ class CbjHubInNetworkWidget extends StatelessWidget { const HubInNetworkEvent.searchHubInNetwork(), ); }, - child: const Text('Retry'), + child: const TextAtom('Retry'), ), ], ); diff --git a/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart b/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart index 64c269a1f..bbf1c8d36 100644 --- a/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart +++ b/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/more_connections_options/more_connections_options_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -33,7 +34,7 @@ class ConnectToHubMorePage extends StatelessWidget { ), Container( alignment: Alignment.center, - child: const Text( + child: const TextAtom( 'More Connections Options', textAlign: TextAlign.center, style: TextStyle( @@ -76,7 +77,7 @@ class ConnectToHubMorePage extends StatelessWidget { backgroundColor: HexColor('#985dc7'), foregroundColor: Colors.white, ), - child: const Text( + child: const TextAtom( 'Back', style: TextStyle(color: Colors.white), ), diff --git a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart index 83eeb4d80..1acb3a58f 100644 --- a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart +++ b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/application/more_connections_options/more_connections_options_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -42,7 +43,7 @@ class ConnectToHubMoreWidget extends StatelessWidget { width: 40, ), Flexible( - child: Text( + child: TextAtom( 'Connect to Remote Pipes', style: TextStyle( color: Colors.white, @@ -54,7 +55,7 @@ class ConnectToHubMoreWidget extends StatelessWidget { ), const Expanded( child: Center( - child: Text( + child: TextAtom( 'Currently not supported', style: TextStyle(color: Colors.white), ), @@ -140,8 +141,8 @@ class ConnectToHubMoreWidget extends StatelessWidget { width: 70, child: CircularProgressIndicator(), ), - loadSuccess: (_) => const Text('Found hub'), - loadFailure: (failure) => const Text('Failure'), + loadSuccess: (_) => const TextAtom('Found hub'), + loadFailure: (failure) => const TextAtom('Failure'), ); }, ); diff --git a/lib/presentation/pages/create_home/create_home_page.dart b/lib/presentation/pages/create_home/create_home_page.dart index 6630c767d..a513415bf 100644 --- a/lib/presentation/pages/create_home/create_home_page.dart +++ b/lib/presentation/pages/create_home/create_home_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/create_home/create_home_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/create_home/widgets/create_home_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -16,7 +17,7 @@ class CreateHomePage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Home Information'), + title: const TextAtom('Home Information'), ), backgroundColor: Colors.blueAccent.withOpacity(0.7), body: Column( diff --git a/lib/presentation/pages/create_home/widgets/create_home_widget.dart b/lib/presentation/pages/create_home/widgets/create_home_widget.dart index 4e591dc1b..692ee90da 100644 --- a/lib/presentation/pages/create_home/widgets/create_home_widget.dart +++ b/lib/presentation/pages/create_home/widgets/create_home_widget.dart @@ -1,6 +1,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/create_home/create_home_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -16,7 +17,7 @@ class CreateHomeWidget extends StatelessWidget { Container( color: Colors.black54, padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), - child: const Text( + child: const TextAtom( 'Name for your home', style: TextStyle(fontSize: 20), ), @@ -53,7 +54,7 @@ class CreateHomeWidget extends StatelessWidget { Container( color: Colors.black54, padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), - child: const Text( + child: const TextAtom( 'Email for the Smart Devices', style: TextStyle(fontSize: 20), ), @@ -89,7 +90,7 @@ class CreateHomeWidget extends StatelessWidget { ), Container( margin: const EdgeInsets.symmetric(horizontal: 48), - child: Text( + child: TextAtom( 'Smart devices needs account to function.\nPlease enter new email.', style: TextStyle( fontSize: 15, @@ -109,7 +110,7 @@ class CreateHomeWidget extends StatelessWidget { .read() .add(CreateHomeEvent.createHome(homeName!, devicesEmail!)); }, - child: Text( + child: TextAtom( 'Create Home', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -120,18 +121,18 @@ class CreateHomeWidget extends StatelessWidget { builder: (context, state) { return state.map( (value) { - return const Text(''); + return const TextAtom(''); }, loading: (loadingNow) { return const CircularProgressIndicator(); }, error: (errorNow) { FlushbarHelper.createError(message: 'Error'); - return const Text('Error'); + return const TextAtom('Error'); }, loaded: (_) { context.router.replace(const HomeRoute()); - return const Text('Loaded'); + return const TextAtom('Loaded'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart index abc870665..6b2253c1b 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart @@ -29,7 +29,7 @@ class BlindsInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart index 80095b0f2..b8186885a 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -51,7 +52,7 @@ class BlindsInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart index 71fb3c6cc..ad44032c0 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/s import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsBlindsPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Blinds'.tr(), + pageName: 'Blinds', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart b/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart index 2d7fcaccc..b3acf5582 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -29,18 +29,20 @@ class SettingsPageOfBlinds extends StatelessWidget { leading: const CircleAvatar( child: FaIcon(FontAwesomeIcons.solidLightbulb), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [lightName]), - subtitle: Text( + translationArgs: [lightName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart index 657a30386..6ff91e2b0 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_value_objects.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -77,7 +78,7 @@ class _SmartBlindPage extends State { final Size screenSize = MediaQuery.of(context).size; return Column( children: [ - Text( + TextAtom( _blind!.cbjEntityName.getOrCrash()!, // Show blind name style: TextStyle( fontSize: 19.0, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart index 7914db615..3845e1f00 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart @@ -1,7 +1,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -71,14 +71,13 @@ class BlindWidget extends StatelessWidget { FontAwesomeIcons.arrowDown, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Down', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 10, @@ -109,14 +108,13 @@ class BlindWidget extends StatelessWidget { FontAwesomeIcons.solidHand, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Stop', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 10, @@ -147,14 +145,13 @@ class BlindWidget extends StatelessWidget { FontAwesomeIcons.arrowUp, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Up', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 10, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart index e4cc15200..4de5fc912 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalFailureBlindsDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalFailureBlindsDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalFailureBlindsDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/error_blind_card_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/error_blind_card_widget.dart index aaf8d2470..6396fa00f 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/error_blind_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/error_blind_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorBlindDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorBlindDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorBlindDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart index 0cfa816e8..4ba499642 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -122,7 +123,7 @@ class RoomBlinds extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds_toggles_block.dart index 3df947c0e..a0ab4e8ed 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds_toggles_block.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -116,7 +117,7 @@ class RoomBlindsTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart index 9d9461938..34217252c 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/blinds/blinds_watcher/blinds_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart'; @@ -96,7 +97,7 @@ class RoomsBlindsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -105,7 +106,7 @@ class RoomsBlindsWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Blinds does not exist.', style: TextStyle( fontSize: 30, @@ -124,7 +125,7 @@ class RoomsBlindsWidget extends StatelessWidget { ); }, blindError: (BlindError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart index 97887041a..31e3c4ff2 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart @@ -29,7 +29,7 @@ class BoilersInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart index f0ba4303a..2e35de364 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -51,7 +52,7 @@ class BoilersInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart index 09b1041ed..b2c98f6e3 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsBoilersPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Boilers'.tr(), + pageName: 'Boilers', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart index 70a5e5c9e..f6d5b15bd 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -29,18 +29,20 @@ class SettingsPageOfBoilers extends StatelessWidget { leading: const CircleAvatar( child: FaIcon(FontAwesomeIcons.solidLightbulb), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [lightName]), - subtitle: Text( + translationArgs: [lightName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart index bea223176..8271acfe6 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_value_objects.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -77,7 +78,7 @@ class _SmartBoilerPage extends State { final Size screenSize = MediaQuery.of(context).size; return Column( children: [ - Text( + TextAtom( _boiler!.cbjEntityName.getOrCrash()!, // Show boiler name style: TextStyle( fontSize: 19.0, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart index c0007a249..eaf23dd1c 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalBoilersFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalBoilersFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalBoilersFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart index af6d2ab9a..3197c8916 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorBoilersDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorBoilersDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorBoilersDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart index cbc05b75b..1aa1cf05b 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:cybear_jinni/application/boilers/boilers_actor/boilers_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart'; import 'package:flutter/material.dart'; @@ -154,7 +155,7 @@ class RoomBoilers extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity!, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers_toggles_block.dart index 363459e05..7bef075d4 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -113,7 +114,7 @@ class RoomBoilersTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart index bfc6aff14..c44e0b12b 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart'; @@ -96,7 +97,7 @@ class RoomsBoilersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -105,7 +106,7 @@ class RoomsBoilersWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Boilers does not exist.', style: TextStyle( fontSize: 30, @@ -124,7 +125,7 @@ class RoomsBoilersWidget extends StatelessWidget { ); }, boilerError: (value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart index 36ecfc968..c4d134a44 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart @@ -31,7 +31,7 @@ class LightsInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart index 186b474ea..fe6a867d1 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -51,7 +52,7 @@ class LightsInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart index 6e671449a..a48847e3e 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/s import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -95,12 +94,12 @@ class RoomsLightsPage extends StatelessWidget { ), body: Container( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Lights'.tr(), + pageName: 'Lights', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart b/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart index a28aab0b8..0ece1e50e 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -29,18 +29,20 @@ class SettingsPageOfLights extends StatelessWidget { leading: const CircleAvatar( child: FaIcon(FontAwesomeIcons.solidLightbulb), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [lightName]), - subtitle: Text( + translationArgs: [lightName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart index cfec6a213..899d7d6bf 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_value_objects.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -77,7 +78,7 @@ class _SmartLightPage extends State { final Size screenSize = MediaQuery.of(context).size; return Column( children: [ - Text( + TextAtom( _light!.cbjEntityName.getOrCrash()!, // Show light name style: TextStyle( fontSize: 19.0, diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart index 44f2aa982..6463f6d57 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalLightFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalLightFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalLightFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart index b58b6ec78..6c4006523 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorLightsDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorLightsDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorLightsDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart index b10cb07be..f8bf06bf6 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; +import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; @@ -57,7 +58,7 @@ class DimmableLightWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( - child: Text( + child: TextAtom( _deviceEntity.cbjEntityName.getOrCrash()!, style: const TextStyle( overflow: TextOverflow.clip, @@ -128,7 +129,7 @@ class DimmableLightWidget extends StatelessWidget { ), SizedBox( width: 45, - child: Text( + child: TextAtom( '${state.brightness.round()}%', style: const TextStyle(color: Colors.black), ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart index 6d0b4c68c..b07449ccc 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart @@ -1,6 +1,6 @@ -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:provider/src/provider.dart'; @@ -114,26 +114,24 @@ class _LightColorMods extends State { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ TextButton( - child: Text( + child: TextAtom( 'White', style: TextStyle( color: (colorModFocus == 0) ? Colors.red : Colors.grey, fontSize: 18, ), - ).tr(), - onPressed: () { + ), onPressed: () { _showWhiteMode(); }, ), TextButton( - child: Text( + child: TextAtom( 'Color', style: TextStyle( color: (colorModFocus == 1) ? Colors.red : Colors.grey, fontSize: 18, ), - ).tr(), - onPressed: () { + ), onPressed: () { _showColorMode(); }, ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart index f0f11b8d9..711ff218a 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; +import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -58,7 +59,7 @@ class RgbwLightWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( - child: Text( + child: TextAtom( _deviceEntity.cbjEntityName.getOrCrash()!, style: const TextStyle( overflow: TextOverflow.clip, @@ -130,7 +131,7 @@ class RgbwLightWidget extends StatelessWidget { ), SizedBox( width: 45, - child: Text( + child: TextAtom( '${state.brightness.round()}%', style: const TextStyle(color: Colors.black), ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart index 740ddf868..b42e5faa6 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart @@ -6,6 +6,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart'; @@ -244,7 +245,7 @@ class RoomLights extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights_toggles_block.dart index 96be6ab01..477bf7cea 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights_toggles_block.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -114,7 +115,7 @@ class RoomLightsTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart index 577822dee..3134c92b4 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart'; @@ -99,7 +100,7 @@ class RoomsLightsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -108,7 +109,7 @@ class RoomsLightsWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Lights does not exist.', style: TextStyle( fontSize: 30, @@ -127,7 +128,7 @@ class RoomsLightsWidget extends StatelessWidget { ); }, lightError: (LightError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart index 94e9729ea..b22ad2543 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -70,7 +71,7 @@ class _SmartPrinterPage extends State { Widget build(BuildContext context) { return Column( children: [ - Text( + TextAtom( _switch!.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, @@ -83,7 +84,7 @@ class _SmartPrinterPage extends State { if (_isLoading) const Center(child: CircularProgressIndicator()) else - const Text('Smart Computer Widget'), + const TextAtom('Smart Computer Widget'), ], ); } diff --git a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart index 5510b3dde..0ee5b0314 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart @@ -29,7 +29,7 @@ class PrintersInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart index 3e5445aa4..234d1135f 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -52,7 +53,7 @@ class PrintersInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart index 8cfd91bef..b5e09ab97 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsPrintersPage extends StatelessWidget { ), body: DecoratedBox( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Smart Computers'.tr(), + pageName: 'Smart Computers', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart b/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart index cf85cf6e3..85a2635a2 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -30,18 +30,20 @@ class SettingsPageOfPrinters extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.lightSwitch), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [switchName]), - subtitle: Text( + translationArgs: [switchName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart index f0848925c..a3208cab2 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalSwitchFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart index 6c42afaef..c91149f76 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorPrintersDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorPrintersDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorPrintersDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart index ad2313126..218194184 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart @@ -1,6 +1,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -66,14 +66,13 @@ class PrinterWidget extends StatelessWidget { FontAwesomeIcons.link, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( "Open Printer's Web Page", style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart index e5e213d49..6a748bae1 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart'; import 'package:flutter/material.dart'; @@ -141,7 +142,7 @@ class RoomPrinters extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers_toggles_block.dart index c17a1cae8..90c71b584 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/printer_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -116,7 +117,7 @@ class RoomPrintersTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart index 389f5ac3e..e90b2d97f 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; @@ -100,7 +101,7 @@ class RoomsPrintersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -109,7 +110,7 @@ class RoomsPrintersWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Printers does not exist.', style: TextStyle( fontSize: 30, @@ -128,7 +129,7 @@ class RoomsPrintersWidget extends StatelessWidget { ); }, printersError: (PrintersError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart index 79ee286ff..f7f3cefe2 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_co import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsSmartComputersPage extends StatelessWidget { ), body: DecoratedBox( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Smart Computers'.tr(), + pageName: 'Smart Computers', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart index 44e2a513c..c7d3a5afe 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -30,18 +30,20 @@ class SettingsPageOfSmartComputers extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.lightSwitch), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [switchName]), - subtitle: Text( + translationArgs: [switchName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart index 1308b93a2..d17c438c0 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -70,7 +71,7 @@ class _SmartSmartComputerPage extends State { Widget build(BuildContext context) { return Column( children: [ - Text( + TextAtom( _switch!.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, @@ -83,7 +84,7 @@ class _SmartSmartComputerPage extends State { if (_isLoading) const Center(child: CircularProgressIndicator()) else - const Text('Smart Computer Widget'), + const TextAtom('Smart Computer Widget'), ], ); } diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart index b84f7c6da..bfd5b1ef6 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart @@ -29,7 +29,7 @@ class SmartComputersInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart index 3f92ede4e..349a36c82 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -52,7 +53,7 @@ class SmartComputersInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart index f0848925c..a3208cab2 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalSwitchFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart index 32232a3e8..ea5af942d 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorSmartComputersDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorSmartComputersDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorSmartComputersDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart index b08b5de3f..8889bd238 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart'; import 'package:flutter/material.dart'; @@ -145,7 +146,7 @@ class RoomSmartComputers extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers_toggles_block.dart index 45b25ffff..9f8068fe4 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -120,7 +121,7 @@ class RoomSmartComputersTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart index 9631d3dfd..418b8a814 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart'; @@ -100,7 +101,7 @@ class RoomsSmartComputersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -109,7 +110,7 @@ class RoomsSmartComputersWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'SmartComputers does not exist.', style: TextStyle( fontSize: 30, @@ -128,7 +129,7 @@ class RoomsSmartComputersWidget extends StatelessWidget { ); }, smartComputersError: (SmartComputersError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart index 3b0ed0208..0a1c02fef 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart @@ -1,6 +1,6 @@ -import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -34,8 +34,6 @@ class SmartComputerWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( listener: (context, state) {}, builder: (context, state) { @@ -66,13 +64,13 @@ class SmartComputerWidget extends StatelessWidget { FontAwesomeIcons.moon, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Sleep', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), + ), ), ), const SizedBox( @@ -99,13 +97,13 @@ class SmartComputerWidget extends StatelessWidget { FontAwesomeIcons.powerOff, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Shutdown', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), + ), ), ), ], diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart index 9470e517a..385479169 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -97,7 +97,7 @@ class RoomsSmartPlugsPage extends StatelessWidget { ), body: Container( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart index 82aee07b3..879890888 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -31,18 +31,20 @@ class SettingsPageOfSmartPlugs extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.powerSocketAu), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [smartPlugName]), - subtitle: Text( + translationArgs: [smartPlugName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart index f1ecdb853..677909210 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_value_objects.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -77,7 +78,7 @@ class _SmartSmartPlugPage extends State { final Size screenSize = MediaQuery.of(context).size; return Column( children: [ - Text( + TextAtom( _smartPlug!.cbjEntityName.getOrCrash()!, // Show smartPlug name style: TextStyle( fontSize: 19.0, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart index da3426262..9dc1b1ee4 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart @@ -31,7 +31,7 @@ class SmartPlugsInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart index 4e354645c..5a9c2ec6c 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -52,7 +53,7 @@ class SmartPlugsInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart index 1b85767db..e05be9aac 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalSmartPlugFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalSmartPlugFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalSmartPlugFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart index 707ba27ba..fe41d805b 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorSmartPlugsDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorSmartPlugsDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorSmartPlugsDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart index 13beb5596..968783ee7 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cybear_jinni/application/smart_plug_toggle/smart_plug_toggle_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart'; import 'package:flutter/material.dart'; @@ -143,7 +144,7 @@ class RoomSmartPlugs extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs_toggles_block.dart index 6903c4279..6f20af6d4 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -116,7 +117,7 @@ class RoomSmartPlugsTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart index 714a7310e..6e6327262 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart'; @@ -101,7 +102,7 @@ class RoomsSmartPlugsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -110,7 +111,7 @@ class RoomsSmartPlugsWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'SmartPlugs does not exist.', style: TextStyle( fontSize: 30, @@ -129,7 +130,7 @@ class RoomsSmartPlugsWidget extends StatelessWidget { ); }, smartPlugsError: (SmartPlugsError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart index ec96ec419..509da8f0a 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart @@ -1,9 +1,9 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsSmartTvsPage extends StatelessWidget { ), body: DecoratedBox( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Smart Tvs'.tr(), + pageName: 'Smart Tvs', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart index 3d32090bb..753549da4 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -30,18 +30,16 @@ class SettingsPageOfSmartTvs extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.lightSwitch), ), - title: Text( - 'Name:_', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ).tr(args: [switchName]), - subtitle: Text( - 'Room:_', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ).tr(args: [roomName]), + title: TextAtom('Name:_', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + translationArgs: [switchName]), + subtitle: TextAtom('Room:_', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + translationArgs: [roomName]), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart index 9031d97b5..e16b328ff 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -70,7 +71,7 @@ class _SmartSmartTvPage extends State { Widget build(BuildContext context) { return Column( children: [ - Text( + TextAtom( _switch!.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, @@ -83,7 +84,7 @@ class _SmartSmartTvPage extends State { if (_isLoading) const Center(child: CircularProgressIndicator()) else - const Text('Smart Tv Widget'), + const TextAtom('Smart Tv Widget'), ], ); } diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart index b5ee20a93..6438e3499 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart @@ -29,7 +29,7 @@ class SmartTvsInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart index 2994a788c..e4522c515 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -52,7 +53,7 @@ class SmartTvsInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/critical_smart_tvs_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/critical_smart_tvs_failure_display_widget.dart index f0848925c..a3208cab2 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/critical_smart_tvs_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/critical_smart_tvs_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalSwitchFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart index 1d0b89201..8edcd17ce 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorSmartTvsDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorSmartTvsDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorSmartTvsDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart index dcd99fef8..042e2e49c 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart @@ -1,5 +1,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -28,7 +29,7 @@ class OpenUrlPopUp { contentPadding: const EdgeInsets.only( top: 10.0, ), - title: const Text( + title: const TextAtom( "Open URL", style: TextStyle(fontSize: 24.0), ), @@ -67,7 +68,7 @@ class OpenUrlPopUp { backgroundColor: Colors.black, // fixedSize: Size(250, 50), ), - child: const Text( + child: const TextAtom( "Submit", ), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart index 2cf51bd09..3cc89dac7 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart'; import 'package:flutter/material.dart'; @@ -142,7 +143,7 @@ class RoomSmartTvs extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs_toggles_block.dart index a7ddde1a2..694031d5c 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -116,7 +117,7 @@ class RoomSmartTvsTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart index 43e8258c0..421bbe49e 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart'; @@ -100,7 +101,7 @@ class RoomsSmartTvsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -109,7 +110,7 @@ class RoomsSmartTvsWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'SmartTvs does not exist.', style: TextStyle( fontSize: 30, @@ -128,7 +129,7 @@ class RoomsSmartTvsWidget extends StatelessWidget { ); }, smartTvsError: (SmartTvsError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart index 2f56d88d3..1bdf4d074 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart @@ -1,7 +1,7 @@ -import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; +import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -113,14 +113,13 @@ class SmartTvWidget extends StatelessWidget { FontAwesomeIcons.video, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Open Video', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 10, @@ -146,14 +145,13 @@ class SmartTvWidget extends StatelessWidget { FontAwesomeIcons.xmark, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Close', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 5, @@ -179,14 +177,13 @@ class SmartTvWidget extends StatelessWidget { FontAwesomeIcons.pause, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Pause', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), const SizedBox( width: 5, @@ -212,14 +209,13 @@ class SmartTvWidget extends StatelessWidget { FontAwesomeIcons.play, color: Theme.of(context).textTheme.bodyLarge!.color, ), - child: Text( + child: TextAtom( 'Play', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ).tr(), - ), + ), ), ), ], ), @@ -253,14 +249,13 @@ class SmartTvWidget extends StatelessWidget { // FontAwesomeIcons.backwardStep, // color: Theme.of(context).textTheme.bodyLarge!.color, // ), - // child: Text( + // child: TextAtom( // 'Queue Prev', // style: TextStyle( // color: Theme.of(context).textTheme.bodyLarge!.color, // fontSize: 16, // ), - // ).tr(), - // ), + // ), // ), // ), // const SizedBox(width: 10), // TextButton( @@ -286,14 +281,13 @@ class SmartTvWidget extends StatelessWidget { // FontAwesomeIcons.forwardStep, // color: Theme.of(context).textTheme.bodyLarge!.color, // ), - // child: Text( + // child: TextAtom( // 'Queue Next', // style: TextStyle( // color: Theme.of(context).textTheme.bodyLarge!.color, // fontSize: 16, // ), - // ).tr(), - // ), + // ), // ), // ), // ], // ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart index 92944436a..7f0c99b5a 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart @@ -11,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -98,12 +97,12 @@ class RoomsSwitchesPage extends StatelessWidget { ), body: Container( decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ TopNavigationBar( - pageName: 'Switches'.tr(), + pageName: 'Switches', rightIcon: null, rightIconFunction: cogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart b/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart index f537b6b36..930ee5a11 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -30,18 +30,20 @@ class SettingsPageOfSwitches extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.lightSwitch), ), - title: Text( + title: TextAtom( 'Name:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [switchName]), - subtitle: Text( + translationArgs: [switchName], + ), + subtitle: TextAtom( 'Room:_', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(args: [roomName]), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, diff --git a/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart index 1ba79096d..cdaa38e00 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_value_objects.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -77,7 +78,7 @@ class _SmartSwitchPage extends State { final Size screenSize = MediaQuery.of(context).size; return Column( children: [ - Text( + TextAtom( _switch!.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, diff --git a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart index 3d635c464..bb9e2da37 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart @@ -31,7 +31,7 @@ class SwitchesInTheRoomPage extends StatelessWidget { body: Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - gradient: BacgroundGradient.getBacground(context), + gradient: BackgroundGradient.getBackground(context), ), child: Column( children: [ diff --git a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart index 5cd3c0c06..ed8798dd7 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -52,7 +53,7 @@ class SwitchesInTheRoomWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - subtitle: Text( + subtitle: TextAtom( products[index]['number'.tr()].toString(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart index f0848925c..a3208cab2 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class CriticalSwitchFailureDisplay extends StatelessWidget { @@ -15,11 +16,11 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - const Text( + const TextAtom( '😱', style: TextStyle(fontSize: 100), ), - const Text( + const TextAtom( 'Unexpected error. \nPlease, contact support', // failure.maybeMap( // insufficientPermission: (_) => 'Insufficient permissions', @@ -35,7 +36,7 @@ class CriticalSwitchFailureDisplay extends StatelessWidget { children: [ Icon(Icons.mail), SizedBox(width: 4), - Text('I NEED HELP'), + TextAtom('I NEED HELP'), ], ), ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart index de6e4431f..97b7b42d6 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorSwitchesDeviceCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorSwitchesDeviceCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid device, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorSwitchesDeviceCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( device!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart index ed4e87c93..94423032d 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart @@ -3,6 +3,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/application/switch_toggle/switch_toggle_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart'; import 'package:flutter/material.dart'; @@ -143,7 +144,7 @@ class RoomSwitches extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _roomEntity, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches_toggles_block.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches_toggles_block.dart index 0214b2c72..f124681a2 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches_toggles_block.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches_toggles_block.dart @@ -1,4 +1,5 @@ import 'package:cbj_integrations_controller/domain/room/smart_room_object.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -116,7 +117,7 @@ class RoomSwitchesTogglesBlock extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( _smartRoomObject!.getRoomName(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart index bb2cc069c..347c7d86e 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart @@ -1,6 +1,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/switches/switches_watcher/switches_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart'; @@ -100,7 +101,7 @@ class RoomsSwitchesWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), @@ -109,7 +110,7 @@ class RoomsSwitchesWidget extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Switches does not exist.', style: TextStyle( fontSize: 30, @@ -128,7 +129,7 @@ class RoomsSwitchesWidget extends StatelessWidget { ); }, switchesError: (SwitchesError value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart b/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart index c37026dbc..e26f176aa 100644 --- a/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart +++ b/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart @@ -1,4 +1,3 @@ -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -20,20 +19,20 @@ class BottomNavigationBarHomePage extends StatelessWidget { BottomNavigationBarItem( activeIcon: Icon(MdiIcons.sitemap), icon: Icon(MdiIcons.sitemapOutline), - label: 'Automations'.tr(), + label: 'Automations', ), BottomNavigationBarItem( activeIcon: Icon(MdiIcons.lightbulbOn), icon: Icon(MdiIcons.lightbulbOutline), - label: 'Devices'.tr(), + label: 'Devices', ), // BottomNavigationBarItem( // icon: const FaIcon(FontAwesomeIcons.history), - // label: 'Routines'.tr(), + // label: 'Routines'. // ), // BottomNavigationBarItem( // icon: const FaIcon(FontAwesomeIcons.link), - // label: 'Bindings'.tr(), + // label: 'Bindings'. // ), ], ); diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index db575c926..eeb0bc9f7 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -1,5 +1,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/bottom_navigation_bar_home_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/left_navigation_drawer_home_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart'; @@ -80,7 +81,7 @@ class _HomePageState extends State { Column( children: [ const Expanded( - child: Text(''), + child: TextAtom(''), ), SizedBox( height: 55, diff --git a/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart b/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart index 67e569dc4..ad5a4148e 100644 --- a/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart +++ b/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart @@ -1,4 +1,5 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/material.dart'; @@ -35,7 +36,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { ), Row( children: [ - Text( + TextAtom( 'Settings', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -51,7 +52,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { children: [ Container( alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_half_app_logo.png', width: 70.0, ), @@ -59,7 +60,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { const SizedBox( width: 20, ), - Text( + TextAtom( 'CyBear Jinni', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -92,7 +93,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Log Out', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -116,7 +117,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Software Info', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -140,7 +141,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Add Remote Control Support', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -164,7 +165,7 @@ class LeftNavigationDrawerHomePage extends StatelessWidget { // color: Theme.of(context).textTheme.bodyLarge!.color, // size: 25, // ), - // title: Text( + // title: TextAtom( // 'Manage Users', // style: TextStyle( // color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/home_page/rooms_manager_widget.dart b/lib/presentation/pages/home_page/rooms_manager_widget.dart index 383059b69..7a0c1d076 100644 --- a/lib/presentation/pages/home_page/rooms_manager_widget.dart +++ b/lib/presentation/pages/home_page/rooms_manager_widget.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; /// This class show all the rooms in the house and quick access to the light switch from the rom_widget page @@ -11,7 +12,7 @@ class RoomsManagerWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return const Text('RoomsManagerWidget'); + return const TextAtom('RoomsManagerWidget'); // Expanded( // child: ListView.builder( // padding: const EdgeInsets.fromLTRB(5, 10, 5, 0), diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart index dace1351b..9bcb09d6d 100644 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart +++ b/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -46,7 +47,7 @@ class AddBindingsPage extends StatelessWidget { const SizedBox( height: 100, ), - const Text( + const TextAtom( 'Press here to set your home location', style: TextStyle(fontSize: 20), ), @@ -62,7 +63,7 @@ class AddBindingsPage extends StatelessWidget { onPressed: () { Navigator.pop(context); }, - child: Text( + child: TextAtom( 'Set Home Location', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -75,7 +76,7 @@ class AddBindingsPage extends StatelessWidget { ), Container( margin: const EdgeInsets.symmetric(horizontal: 20), - child: const Text( + child: const TextAtom( 'By pressing here you allow the app to access your location' ' even when the app is not open.', style: TextStyle(fontSize: 14), diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart index c20057a62..d9ab2ce48 100644 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart +++ b/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart @@ -1,4 +1,5 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; @@ -13,7 +14,7 @@ class BindingsPage extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '⚙️ Bindings Settings', style: TextStyle(color: Colors.blueGrey, fontSize: 23), ), @@ -65,14 +66,14 @@ class BindingsPage extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), ), Align( alignment: Alignment.topCenter, - child: Text( + child: TextAtom( 'Bindings list is empty', style: TextStyle( fontSize: 30, @@ -89,7 +90,7 @@ class BindingsPage extends StatelessWidget { Column( children: [ const Expanded( - child: Text(''), + child: TextAtom(''), ), SizedBox( height: 100, diff --git a/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart b/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart index d455b6548..88eebff42 100644 --- a/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart +++ b/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart @@ -1,5 +1,5 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -26,18 +26,18 @@ class HistoryTab extends StatelessWidget { ), ), ), - Text( + TextAtom( 'Actions_History', style: TextStyle( fontSize: 23.0, color: Theme.of(context).textTheme.bodyLarge!.color, decoration: TextDecoration.underline, ), - ).tr(), + ), Container( height: 20, ), - const Text('Empty_history').tr(), + const TextAtom('Empty_history'), ], ); } diff --git a/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart b/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart index 5190d9bac..ad18e4b4d 100644 --- a/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart +++ b/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart @@ -1,4 +1,4 @@ -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -45,14 +45,14 @@ class SettingsPageOfHistory extends StatelessWidget { onPressed: () => Navigator.pop(context), ), ), - Text( + TextAtom( 'History_Settings_Page', style: TextStyle( fontSize: 23.0, color: Theme.of(context).textTheme.bodyLarge!.color, decoration: TextDecoration.underline, ), - ).tr(), + ), ], ), ), 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 085ed7fb0..f5529186a 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 @@ -1,9 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:cybear_jinni/application/folders_of_scenes/folders_of_scenes_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -16,7 +16,7 @@ class ScenesInFoldersTab extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '⚙️ Scenes Settings', style: TextStyle( color: Colors.blueGrey, @@ -49,7 +49,7 @@ class ScenesInFoldersTab extends StatelessWidget { return Column( children: [ TopNavigationBar( - pageName: 'Automations'.tr(), + pageName: 'Automations', rightIcon: null, rightIconFunction: userCogFunction, leftIcon: FontAwesomeIcons.sitemap, diff --git a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart index 9c88b8905..76a8ae569 100644 --- a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart +++ b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/folders_of_scenes/folders_of_scenes_bloc.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cybear_jinni/application/folders_of_scenes/folders_of_scenes_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,7 +12,7 @@ class ScenesInFoldersL extends StatelessWidget { return BlocBuilder( builder: (context, state) { return state.map( - (value) => const Text('sd'), + (value) => const TextAtom('sd'), loading: (_) => const Center( child: CircularProgressIndicator(), ), @@ -31,7 +32,7 @@ class ScenesInFoldersL extends StatelessWidget { }, loadedEmpty: (LoadedEmpty value) { return const Center( - child: Text( + child: TextAtom( 'You can add automations in the plus button', style: TextStyle( fontSize: 18, @@ -41,7 +42,7 @@ class ScenesInFoldersL extends StatelessWidget { ); }, error: (_) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, @@ -96,7 +97,7 @@ class ScenesInFoldersL extends StatelessWidget { bottomLeft: Radius.circular(borderRadius), ), ), - child: Text( + child: TextAtom( folderOfScenes.cbjEntityName.getOrCrash(), style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart index c41412394..665868790 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -70,7 +71,7 @@ class BlindsInTheRoom extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -104,7 +105,7 @@ class BlindsInTheRoom extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( blindsInRoom!.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -116,7 +117,7 @@ class BlindsInTheRoom extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), @@ -175,7 +176,7 @@ class BlindsInTheRoom extends StatelessWidget { color: Theme.of(context).textTheme.bodyMedium!.color, ), ), - Text( + TextAtom( '·', style: TextStyle( fontSize: 14, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart index 418f705d1..d051a0f29 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -68,7 +69,7 @@ class BoilersInTheRoom extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -102,7 +103,7 @@ class BoilersInTheRoom extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( boilersInRoom!.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -114,7 +115,7 @@ class BoilersInTheRoom extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox( diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart index 6f7ed2041..49843497c 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart @@ -7,6 +7,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; import 'package:cybear_jinni/application/lights/lights_actor/lights_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/utils.dart'; @@ -106,7 +107,7 @@ class LightsInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -140,7 +141,7 @@ class LightsInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( totalLightsInTheRoom.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -152,7 +153,7 @@ class LightsInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), @@ -203,15 +204,14 @@ class LightsInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'Off', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), - Text( + ), ), + TextAtom( '·', style: TextStyle( fontSize: 14, @@ -235,14 +235,13 @@ class LightsInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'On', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), + ), ), ], ); }, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/printers_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/printers_in_the_room_block.dart index a56e979ba..59d6f1d1d 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/printers_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/printers_in_the_room_block.dart @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -69,7 +70,7 @@ class PrintersInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -103,7 +104,7 @@ class PrintersInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( printersInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -115,7 +116,7 @@ class PrintersInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart index 77342ae28..00a2cc5b3 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_security_camera_device/generic_security_camera_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -66,7 +67,7 @@ class SecurityCamerasInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -100,7 +101,7 @@ class SecurityCamerasInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( securityCamerasInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -112,7 +113,7 @@ class SecurityCamerasInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_computers_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_computers_in_the_room_block.dart index 9148eb1ef..bf12b26fc 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_computers_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_computers_in_the_room_block.dart @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -69,7 +70,7 @@ class SmartComputersInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -103,7 +104,7 @@ class SmartComputersInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( smartComputersInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -115,7 +116,7 @@ class SmartComputersInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart index ca8209d84..9734f2268 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -71,7 +72,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -105,7 +106,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( smartPlugsInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -117,7 +118,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), @@ -168,15 +169,14 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'Off', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), - Text( + ), ), + TextAtom( '·', style: TextStyle( fontSize: 14, @@ -200,14 +200,13 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'On', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), + ), ), ], ); }, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart index 462d5557b..d0dea4d34 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart @@ -3,6 +3,7 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -69,7 +70,7 @@ class SmartTvInTheRoom extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -103,7 +104,7 @@ class SmartTvInTheRoom extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( smartTvsInRoom!.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -115,7 +116,7 @@ class SmartTvInTheRoom extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 10), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart index dc99e5b44..ce5028235 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart @@ -4,6 +4,7 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/application/switches/switches_actor/switches_actor_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -71,7 +72,7 @@ class SwitchesInTheRoomBlock extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), Expanded( child: Column( children: [ @@ -105,7 +106,7 @@ class SwitchesInTheRoomBlock extends StatelessWidget { ), borderRadius: BorderRadius.circular(10), ), - child: Text( + child: TextAtom( switchesInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( @@ -117,7 +118,7 @@ class SwitchesInTheRoomBlock extends StatelessWidget { ), ) else - const Expanded(child: Text('')), + const Expanded(child: TextAtom('')), ], ), const SizedBox(height: 5), @@ -168,15 +169,14 @@ class SwitchesInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'Off', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), - Text( + ), ), + TextAtom( '·', style: TextStyle( fontSize: 14, @@ -200,14 +200,13 @@ class SwitchesInTheRoomBlock extends StatelessWidget { ), ); }, - child: Text( + child: TextAtom( 'On', style: TextStyle( fontSize: 14, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ), + ), ), ], ); }, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart index 4cd195763..e958bb94a 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart @@ -11,6 +11,7 @@ import 'package:cybear_jinni/application/smart_plugs/smart_plugs_actor/smart_plu import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; import 'package:cybear_jinni/application/switches/switches_actor/switches_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/boilers_in_the_room.dart'; @@ -22,7 +23,6 @@ import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_tv_in_the_room.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart'; import 'package:cybear_jinni/utils.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -98,7 +98,7 @@ class RoomWidget extends StatelessWidget { alignment: Alignment.topCenter, child: Stack( children: [ - Text( + TextAtom( roomsList .firstWhere( (element) => @@ -114,7 +114,7 @@ class RoomWidget extends StatelessWidget { ..color = Colors.black, ), ), - Text( + TextAtom( roomsList .firstWhere( (element) => @@ -131,15 +131,17 @@ class RoomWidget extends StatelessWidget { ), ), if (numberOfDevicesInTheRoom == 1) - const Text( + TextAtom( '_device', style: TextStyle(fontSize: 12), - ).tr(args: [numberOfDevicesInTheRoom.toString()]) + translationArgs: [numberOfDevicesInTheRoom.toString()], + ) else - const Text( + TextAtom( '_devices', style: TextStyle(fontSize: 12), - ).tr(args: [numberOfDevicesInTheRoom.toString()]), + translationArgs: [numberOfDevicesInTheRoom.toString()], + ), /// Build the devices in the room by type GridView.builder( @@ -304,7 +306,7 @@ class RoomWidget extends StatelessWidget { color: Colors.red, ), ), - Text( + TextAtom( 'Unsupported Type', style: TextStyle(color: Colors.white), ), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart index 1ffdb1d31..ad20be115 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart @@ -15,6 +15,7 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/ad_state.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart'; @@ -430,7 +431,7 @@ class _RoomsListViewWidgetState extends State { numberOfDevicesInTheRoom: numberOfDevicesInTheRoom, ); } - return const Text('Error'); + return const TextAtom('Error'); }, itemCount: objectList.length, ); diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart index 6041bb3f7..62268bbe8 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -53,7 +54,7 @@ class SettingsPageSmartDevices extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'Open Access Point', style: TextStyle( fontSize: 25, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart index 0469c34a3..251b0b545 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart @@ -1,8 +1,8 @@ -import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -21,7 +21,7 @@ class SmartDevicesByRooms extends StatelessWidget { SizedBox( height: 30, ), - Text( + TextAtom( 'Searching for CyBear Jinni Hub', style: TextStyle( fontSize: 18, @@ -46,7 +46,7 @@ class SmartDevicesByRooms extends StatelessWidget { Container( margin: const EdgeInsets.only(bottom: 10), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', width: 200.0, fit: BoxFit.fill, @@ -61,7 +61,7 @@ class SmartDevicesByRooms extends StatelessWidget { ), child: Stack( children: [ - Text( + TextAtom( 'Areas', style: TextStyle( fontSize: 35, @@ -70,15 +70,15 @@ class SmartDevicesByRooms extends StatelessWidget { ..strokeWidth = 3 ..color = Colors.black.withOpacity(0.2), ), - ).tr(), - Text( + ), + TextAtom( 'Areas', style: TextStyle( fontSize: 35, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), + ), ], ), ), @@ -110,14 +110,14 @@ class SmartDevicesByRooms extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), ), Align( alignment: Alignment.topCenter, - child: Text( + child: TextAtom( 'Devices list is empty', style: TextStyle( fontSize: 30, @@ -137,7 +137,7 @@ class SmartDevicesByRooms extends StatelessWidget { ); }, error: (Error value) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart index 04988321a..3339e0efd 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart @@ -5,11 +5,11 @@ import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -21,7 +21,7 @@ class SmartDevicesWidgets extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '⚙️ Change Area For Devices', style: TextStyle(color: Colors.blueGrey, fontSize: 23), ), @@ -103,7 +103,7 @@ class SmartDevicesWidgets extends StatelessWidget { child: Column( children: [ TopNavigationBar( - pageName: 'Devices'.tr(), + pageName: 'Devices', rightIcon: Icons.more_vert, rightIconFunction: userCogFunction, leftIcon: FontAwesomeIcons.solidLightbulb, diff --git a/lib/presentation/pages/introduction_screen/introduction_screen_body.dart b/lib/presentation/pages/introduction_screen/introduction_screen_body.dart index 628895c96..35e31aa21 100644 --- a/lib/presentation/pages/introduction_screen/introduction_screen_body.dart +++ b/lib/presentation/pages/introduction_screen/introduction_screen_body.dart @@ -1,4 +1,5 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_about_page.dart'; import 'package:cybear_jinni/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_welcome_page.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; @@ -44,7 +45,7 @@ class IntroductionScreenBody extends StatelessWidget { Container( margin: const EdgeInsets.only(top: 20, bottom: 5), child: Center( - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', height: 200.0, ), @@ -52,7 +53,7 @@ class IntroductionScreenBody extends StatelessWidget { ), Stack( children: [ - Text( + TextAtom( 'CyBear Jinni', style: TextStyle( fontSize: 48, @@ -62,7 +63,7 @@ class IntroductionScreenBody extends StatelessWidget { ..color = Colors.pink.withOpacity(0.13), ), ), - Text( + TextAtom( 'CyBear Jinni', style: TextStyle( fontSize: 48, @@ -93,7 +94,7 @@ class IntroductionScreenBody extends StatelessWidget { const SizedBox( height: 40, ), - Text( + TextAtom( 'Our Vision', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -117,7 +118,7 @@ class IntroductionScreenBody extends StatelessWidget { ), ), ], - done: Text( + done: TextAtom( 'Done', style: TextStyle( fontWeight: FontWeight.w600, diff --git a/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_about_page.dart b/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_about_page.dart index e1aa56b7f..9b2464e0c 100644 --- a/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_about_page.dart +++ b/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_about_page.dart @@ -1,3 +1,4 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class IntroductionScreenBodyAboutPage extends StatelessWidget { @@ -21,7 +22,7 @@ class IntroductionScreenBodyAboutPage extends StatelessWidget { child: Container( padding: const EdgeInsets.all(20), child: const SingleChildScrollView( - child: Text( + child: TextAtom( 'You are now starting a journey into the world of CyBear ' 'Jinni.\n\nWe are trying to build an ecosystem of smart' ' home that is built upon openness and trust.\n\n' diff --git a/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_welcome_page.dart b/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_welcome_page.dart index 96a8024b6..4bae29077 100644 --- a/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_welcome_page.dart +++ b/lib/presentation/pages/introduction_screen/introductions_view_model_body/introduction_screen_body_welcome_page.dart @@ -1,4 +1,5 @@ import 'package:animated_text_kit/animated_text_kit.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class IntroductionScreenBodyWelcomePage extends StatelessWidget { @@ -10,7 +11,7 @@ class IntroductionScreenBodyWelcomePage extends StatelessWidget { height: 60, child: Row( children: [ - Text( + TextAtom( 'We', style: TextStyle( fontSize: 17.0, diff --git a/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart b/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart index 634c649c5..5afa90a14 100644 --- a/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart +++ b/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/join_home_by_id/join_home_by_id_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,7 +12,7 @@ class JoinHomeByIdPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Add home by ID'), + title: const TextAtom('Add home by ID'), ), backgroundColor: Colors.blueAccent.withOpacity(0.7), body: BlocProvider( diff --git a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart b/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart index c5536782e..b679c2f2e 100644 --- a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart +++ b/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:clipboard/clipboard.dart'; import 'package:cybear_jinni/application/join_home_by_id/join_home_by_id_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -21,10 +22,10 @@ class JoinHomeByIdWidget extends StatelessWidget { ); }, loaded: (l) { - return const Text('Loaded'); + return const TextAtom('Loaded'); }, error: (e) { - return const Text('Failure'); + return const TextAtom('Failure'); }, ); }, @@ -45,7 +46,7 @@ class JoinHomeByIdWidget extends StatelessWidget { .read() .add(JoinHomeByIdEvent.addHomeById(fromClipboard)); }, - child: Text( + child: TextAtom( 'Paste and search', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -60,7 +61,7 @@ class JoinHomeByIdWidget extends StatelessWidget { const SizedBox( width: 10, ), - const Text('Home ID'), + const TextAtom('Home ID'), const SizedBox( width: 30, ), @@ -102,7 +103,7 @@ class JoinHomeByIdWidget extends StatelessWidget { .read() .add(JoinHomeByIdEvent.addHomeById(homeId)); }, - child: Text( + child: TextAtom( 'Join Home from text form', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, @@ -120,10 +121,10 @@ class JoinHomeByIdWidget extends StatelessWidget { loaded: (l) { context.router.replace(const HomeRoute()); - return const Text('Loaded'); + return const TextAtom('Loaded'); }, error: (e) { - return const Text('Failure'); + return const TextAtom('Failure'); }, ), ], diff --git a/lib/presentation/pages/manage_users/manage_users_page.dart b/lib/presentation/pages/manage_users/manage_users_page.dart index 205c56301..d7a34a3a0 100644 --- a/lib/presentation/pages/manage_users/manage_users_page.dart +++ b/lib/presentation/pages/manage_users/manage_users_page.dart @@ -3,6 +3,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/manage_users/manage_users_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/manage_users/widgets/manage_users_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; @@ -19,7 +20,7 @@ class ManageUsersPage extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '➕ Add User', style: TextStyle(color: Colors.green, fontSize: 23), ), diff --git a/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart b/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart index 63de8a41d..295b17b81 100644 --- a/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart +++ b/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorUserCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorUserCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid user, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorUserCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( homeUser!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart b/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart index 3d508aa1d..e4964f80e 100644 --- a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart +++ b/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/application/manage_users/manage_users_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/manage_users/widgets/error_user_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/manage_users/widgets/user_card_widget.dart'; import 'package:flutter/material.dart'; @@ -9,9 +10,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class ManageUsersWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - final double sizeBoxWidth = screenSize.width * 0.25; - return BlocBuilder( builder: (context, state) { return state.map( @@ -38,19 +36,19 @@ class ManageUsersWidget extends StatelessWidget { ); }, loadFailure: (state) { - return const Text('Load Failure'); + return const TextAtom('Load Failure'); }, addSuccess: (state) { - return const Text('Add Success'); + return const TextAtom('Add Success'); }, deleteFailure: (state) { - return const Text('Delete Failure'); + return const TextAtom('Delete Failure'); }, deleteSuccess: (state) { - return const Text('Delete Success'); + return const TextAtom('Delete Success'); }, error: (state) { - return const Text('Error'); + return const TextAtom('Error'); }, ); }, diff --git a/lib/presentation/pages/manage_users/widgets/user_card_widget.dart b/lib/presentation/pages/manage_users/widgets/user_card_widget.dart index 6830e1586..e4d1b3ace 100644 --- a/lib/presentation/pages/manage_users/widgets/user_card_widget.dart +++ b/lib/presentation/pages/manage_users/widgets/user_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -33,7 +34,7 @@ class UserCard extends StatelessWidget { title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( homeUser!.email!.getOrCrash()!, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/plus_button/plus_button.dart b/lib/presentation/pages/plus_button/plus_button.dart index cec51aabe..36381d95e 100644 --- a/lib/presentation/pages/plus_button/plus_button.dart +++ b/lib/presentation/pages/plus_button/plus_button.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/plus_button_settings/plus_button_settings_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/plus_button/widgets/plus_button_wighet.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,7 +12,7 @@ class PlusButtonPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Add and Manage'), + title: const TextAtom('Add and Manage'), backgroundColor: Colors.purple.withOpacity(0.7), ), backgroundColor: Colors.black.withOpacity(0.7), diff --git a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart index 05593e367..dead13c5a 100644 --- a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart +++ b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/plus_button_settings/plus_button_settings_bloc.dart'; import 'package:cybear_jinni/domain/hub/hub_entity.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -26,7 +27,7 @@ class PlusButtonWidget extends StatelessWidget { Container( padding: const EdgeInsets.symmetric(horizontal: 15), alignment: Alignment.topLeft, - child: const Text( + child: const TextAtom( 'Add:', style: TextStyle( color: Colors.white, @@ -51,7 +52,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Turn Phone To a Security Camera', style: TextStyle( color: Theme.of(context) @@ -81,7 +82,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Add Device', style: TextStyle( color: Theme.of(context) @@ -106,7 +107,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Add Remote Control Support', style: TextStyle( color: Theme.of(context) @@ -130,7 +131,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Add Automation', style: TextStyle( color: Theme.of(context) @@ -155,7 +156,7 @@ class PlusButtonWidget extends StatelessWidget { Container( alignment: Alignment.topLeft, padding: const EdgeInsets.symmetric(horizontal: 15), - child: const Text( + child: const TextAtom( 'Manage:', style: TextStyle( color: Colors.white, @@ -182,7 +183,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 23, ), - title: Text( + title: TextAtom( 'Open Node-RED of Hub', style: TextStyle( color: Theme.of(context) @@ -206,7 +207,7 @@ class PlusButtonWidget extends StatelessWidget { showDialog( context: context, builder: (_) => const AlertDialog( - title: Text( + title: TextAtom( "Can't find Hub/Node-Red IP to connect to", ), ), @@ -227,7 +228,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Software Info', style: TextStyle( color: Theme.of(context) @@ -253,7 +254,7 @@ class PlusButtonWidget extends StatelessWidget { Theme.of(context).textTheme.bodyLarge!.color, size: 25, ), - title: Text( + title: TextAtom( 'Log Out', style: TextStyle( color: Theme.of(context) @@ -282,8 +283,8 @@ class PlusButtonWidget extends StatelessWidget { loadInProgress: (_) => const Center( child: CircularProgressIndicator(), ), - loadSuccess: (_) => const Text('Found hub'), - loadFailure: (failure) => const Text('Failure'), + loadSuccess: (_) => const TextAtom('Found hub'), + loadFailure: (failure) => const TextAtom('Failure'), ); }, ); diff --git a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart index af043edd7..775cdc622 100644 --- a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart +++ b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart @@ -3,6 +3,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/remote_pipes/remote_pipes_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; @@ -19,7 +20,7 @@ class RemotePipesPage extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '➕ Add remote pipes', style: TextStyle(color: Colors.green, fontSize: 23), ), diff --git a/lib/presentation/pages/remote_pipes/widgets/error_remote_pipes_card_widget.dart b/lib/presentation/pages/remote_pipes/widgets/error_remote_pipes_card_widget.dart index 0f1961da1..396c0dea5 100644 --- a/lib/presentation/pages/remote_pipes/widgets/error_remote_pipes_card_widget.dart +++ b/lib/presentation/pages/remote_pipes/widgets/error_remote_pipes_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorRemotePipesCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorRemotePipesCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid remote pipes, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorRemotePipesCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( homeUser!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart b/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart index 5df2f7513..8d237fdd8 100644 --- a/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart +++ b/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/application/remote_pipes/remote_pipes_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; @@ -16,7 +17,7 @@ class RemotePipesWidget extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( + const TextAtom( 'Please insert the Remote Pipes domain', style: TextStyle(color: Colors.black, fontSize: 25), ), @@ -64,7 +65,7 @@ class RemotePipesWidget extends StatelessWidget { RemotePipesEvent.addRemotePipeUrl(context), ); }, - child: const Text('Connect'), + child: const TextAtom('Connect'), ), ], ), diff --git a/lib/presentation/pages/remote_pipes/widgets/remote_pipes_card_widget.dart b/lib/presentation/pages/remote_pipes/widgets/remote_pipes_card_widget.dart index 058180af6..411b80674 100644 --- a/lib/presentation/pages/remote_pipes/widgets/remote_pipes_card_widget.dart +++ b/lib/presentation/pages/remote_pipes/widgets/remote_pipes_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -33,7 +34,7 @@ class RemotePipesCard extends StatelessWidget { title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( homeUser!.email!.getOrCrash()!, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/scenes/scenes_page.dart b/lib/presentation/pages/scenes/scenes_page.dart index 96e3b012a..55f182f55 100644 --- a/lib/presentation/pages/scenes/scenes_page.dart +++ b/lib/presentation/pages/scenes/scenes_page.dart @@ -2,12 +2,12 @@ import 'dart:ui'; import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/folder_of_scenes/folder_of_scenes_bloc.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cybear_jinni/application/folder_of_scenes/folder_of_scenes_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/scenes/widgets/folder_of_scenes.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -25,14 +25,14 @@ class ScenesPage extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '➕ Add Automation', style: TextStyle(color: Colors.green, fontSize: 23), ), onPressed: (_) {}, ), BottomSheetAction( - title: const Text( + title: const TextAtom( '⚙️ Scenes Settings', style: TextStyle(color: Colors.blueGrey, fontSize: 23), ), @@ -70,7 +70,7 @@ class ScenesPage extends StatelessWidget { child: Column( children: [ TopNavigationBar( - pageName: 'Scenes_In_Folder'.tr(), + pageName: 'Scenes_In_Folder', rightIcon: null, rightIconFunction: userCogFunction, leftIcon: FontAwesomeIcons.arrowLeft, diff --git a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart index b24a88a51..1c4768997 100644 --- a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart +++ b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart @@ -5,6 +5,7 @@ import 'package:cbj_integrations_controller/domain/scene/scene_cbj_failures.dart import 'package:cybear_jinni/application/folder_of_scenes/folder_of_scenes_bloc.dart'; import 'package:cybear_jinni/application/scene/scene_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/scenes/widgets/scene_widget.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; @@ -34,22 +35,22 @@ class FolderOfScenesWidget extends StatelessWidget { listener: (context, FolderOfScenesState state) { state.map( (value) => (v) { - return const Text('value'); + return const TextAtom('value'); }, loading: (loadingNow) { - return const Text('loading'); + return const TextAtom('loading'); }, error: (errorNow) { FlushbarHelper.createError(message: 'Error'); }, - loaded: (_) => const Text('Loaded'), + loaded: (_) => const TextAtom('Loaded'), loadedEmptyScens: (LoadedEmptyScens value) {}, ); }, builder: (context, state) { return state.map( - (value) => const Text('Start'), - loading: (_) => const Text('loading'), + (value) => const TextAtom('Start'), + loading: (_) => const TextAtom('loading'), loaded: (scenesList) { return GridView.builder( reverse: true, @@ -73,7 +74,7 @@ class FolderOfScenesWidget extends StatelessWidget { }, loadedEmptyScens: (LoadedEmptyScens value) { return const Center( - child: Text( + child: TextAtom( 'You can add automations in the plus button', style: TextStyle( fontSize: 18, @@ -82,7 +83,7 @@ class FolderOfScenesWidget extends StatelessWidget { ), ); }, - error: (_) => const Text('error'), + error: (_) => const TextAtom('error'), ); }, ); diff --git a/lib/presentation/pages/scenes/widgets/scene_widget.dart b/lib/presentation/pages/scenes/widgets/scene_widget.dart index 4299a13a2..0133ae3b1 100644 --- a/lib/presentation/pages/scenes/widgets/scene_widget.dart +++ b/lib/presentation/pages/scenes/widgets/scene_widget.dart @@ -1,6 +1,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cybear_jinni/application/scene/scene_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -21,13 +22,13 @@ class SceneWidget extends StatelessWidget { error: (errorNow) { FlushbarHelper.createError(message: 'Error'); }, - loaded: (_) => const Text('loaded'), + loaded: (_) => const TextAtom('loaded'), ); }, builder: (context, state) { return state.map( - (value) => const Text('value'), - loading: (_) => const Text('Loading'), + (value) => const TextAtom('value'), + loading: (_) => const TextAtom('Loading'), loaded: (sceneState) { return Container( margin: const EdgeInsets.fromLTRB(5, 0, 5, 10), @@ -74,7 +75,7 @@ class SceneWidget extends StatelessWidget { color: Colors.black54, ), alignment: Alignment.center, - child: Text( + child: TextAtom( currentScene.name.getOrCrash(), style: TextStyle( fontSize: 23, @@ -86,7 +87,7 @@ class SceneWidget extends StatelessWidget { ), ); }, - error: (_) => const Text('Error'), + error: (_) => const TextAtom('Error'), ); }, ); diff --git a/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart b/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart index a3e3a3728..a81fc73a3 100644 --- a/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart +++ b/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart @@ -1,5 +1,6 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:network_info_plus/network_info_plus.dart'; @@ -38,7 +39,7 @@ class _AddNewDeviceWidgetPopup extends State { return null; }, decoration: InputDecoration( - labelText: 'IP'.tr(), + labelText: 'IP' ), ); } else { @@ -54,7 +55,7 @@ class _AddNewDeviceWidgetPopup extends State { return Form( key: _formKey, child: AlertDialog( - title: const Text('Add_Smart_Device').tr(), + title: const TextAtom('Add_Smart_Device'), content: SingleChildScrollView( child: addNewDeviceWidget, ), @@ -63,7 +64,7 @@ class _AddNewDeviceWidgetPopup extends State { onPressed: () { Navigator.of(context).pop(); }, - child: const Text('Cancel').tr(), + child: const TextAtom('Cancel'), ), TextButton( onPressed: () { @@ -71,7 +72,7 @@ class _AddNewDeviceWidgetPopup extends State { // rooms[0].getLights()[0] = // SmartDeviceObject(_deviceType, _deviceName, _ip, _roomName); }, - child: const Text('Add').tr(), + child: const TextAtom('Add'), ), ], ), @@ -110,7 +111,7 @@ class _DropDownMenu extends State { ].map>((String value) { return DropdownMenuItem( value: value, - child: Text(value), + child: TextAtom(value), ); }).toList(), ); diff --git a/lib/presentation/pages/shared_widgets/smart_device_type_and_toggle_bar.dart b/lib/presentation/pages/shared_widgets/smart_device_type_and_toggle_bar.dart index 01584a6b5..8eab057c9 100644 --- a/lib/presentation/pages/shared_widgets/smart_device_type_and_toggle_bar.dart +++ b/lib/presentation/pages/shared_widgets/smart_device_type_and_toggle_bar.dart @@ -1,8 +1,8 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -34,7 +34,7 @@ class SmartDeviceTypeAndToggleBar extends StatelessWidget { child: FaIcon(FontAwesomeIcons.satelliteDish), ), ), - Text( + TextAtom( 'Device_type:_', textAlign: TextAlign.center, style: TextStyle( @@ -44,7 +44,8 @@ class SmartDeviceTypeAndToggleBar extends StatelessWidget { // color: (Theme.of(context).textTheme.bodyLarge!.color)!, , ), - ).tr(args: [EnumHelperCbj.dTToString(deviceType)]), + translationArgs: [EnumHelperCbj.dTToString(deviceType)], + ), if (deviceType == EntityTypes.light) SizedBox( width: 100, diff --git a/lib/presentation/pages/shared_widgets/top_navigation_bar.dart b/lib/presentation/pages/shared_widgets/top_navigation_bar.dart index 26244d76b..5814d1e62 100644 --- a/lib/presentation/pages/shared_widgets/top_navigation_bar.dart +++ b/lib/presentation/pages/shared_widgets/top_navigation_bar.dart @@ -1,4 +1,4 @@ -import 'package:easy_localization/easy_localization.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -67,14 +67,13 @@ class TopNavigationBar extends StatelessWidget { ) else const SizedBox(), - Text( + TextAtom( pageName!, style: TextStyle( fontSize: 16.0, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ).tr(), - ], + ), ], ), if (rightIcon != null) Row( diff --git a/lib/presentation/pages/sign_in_page/sign_in_page.dart b/lib/presentation/pages/sign_in_page/sign_in_page.dart index 292cb6c4c..e63781145 100644 --- a/lib/presentation/pages/sign_in_page/sign_in_page.dart +++ b/lib/presentation/pages/sign_in_page/sign_in_page.dart @@ -1,6 +1,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/sign_in_form/sign_in_form_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,7 +12,7 @@ class SignInPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Sign In'), + title: const TextAtom('Sign In'), ), body: BlocProvider( create: (context) => getIt(), diff --git a/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart b/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart index 7d991fcde..c8d8c38b9 100644 --- a/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart +++ b/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart @@ -2,6 +2,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/auth/sign_in_form/sign_in_form_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -49,7 +50,7 @@ class SignInFormWidget extends StatelessWidget { child: CircleAvatar( backgroundColor: Colors.transparent, radius: screenSize.height * 0.1, - child: Image.asset('assets/cbj_logo.png'), + child: ImageAtom('assets/cbj_logo.png'), ), ), const SizedBox( @@ -115,7 +116,7 @@ class SignInFormWidget extends StatelessWidget { .signInWithEmailAndPasswordPassed(), ); }, - child: const Text('SIGN IN'), + child: const TextAtom('SIGN IN'), ), ), Expanded( @@ -126,7 +127,7 @@ class SignInFormWidget extends StatelessWidget { .registerWithEmailAndPassword(), ); }, - child: const Text('REGISTER'), + child: const TextAtom('REGISTER'), ), ), ], @@ -152,7 +153,7 @@ class SignInFormWidget extends StatelessWidget { onPressed: () { context.router.push(const WhereToLoginRouteOffline()); }, - child: Text( + child: TextAtom( 'For More Options', style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/software_info/software_info_page.dart b/lib/presentation/pages/software_info/software_info_page.dart index 45375db24..67123adb0 100644 --- a/lib/presentation/pages/software_info/software_info_page.dart +++ b/lib/presentation/pages/software_info/software_info_page.dart @@ -3,6 +3,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/software_info/software_info_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/presentation/pages/software_info/widgets/software_info_widget.dart'; @@ -19,7 +20,7 @@ class SoftwareInfoPage extends StatelessWidget { context: context, actions: [ BottomSheetAction( - title: const Text( + title: const TextAtom( '➕ Add software nfo', style: TextStyle(color: Colors.green, fontSize: 23), ), diff --git a/lib/presentation/pages/software_info/widgets/error_software_info_card_widget.dart b/lib/presentation/pages/software_info/widgets/error_software_info_card_widget.dart index 861f0f6be..d28f0e8fa 100644 --- a/lib/presentation/pages/software_info/widgets/error_software_info_card_widget.dart +++ b/lib/presentation/pages/software_info/widgets/error_software_info_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorSoftwareInfoCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorSoftwareInfoCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid software nfo, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorSoftwareInfoCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( homeUser!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/software_info/widgets/software_info_card_widget.dart b/lib/presentation/pages/software_info/widgets/software_info_card_widget.dart index b63e54ada..b56f634b2 100644 --- a/lib/presentation/pages/software_info/widgets/software_info_card_widget.dart +++ b/lib/presentation/pages/software_info/widgets/software_info_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -33,7 +34,7 @@ class SoftwareInfoCard extends StatelessWidget { title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( homeUser!.email!.getOrCrash()!, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/software_info/widgets/software_info_widget.dart b/lib/presentation/pages/software_info/widgets/software_info_widget.dart index be24e80fd..0e2997cdd 100644 --- a/lib/presentation/pages/software_info/widgets/software_info_widget.dart +++ b/lib/presentation/pages/software_info/widgets/software_info_widget.dart @@ -1,5 +1,6 @@ import 'package:cybear_jinni/application/software_info/software_info_bloc.dart'; import 'package:cybear_jinni/domain/software_info/software_info_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -27,7 +28,7 @@ class SoftwareInfoWidget extends StatelessWidget { softwareInfoEntities[key]; return Column( children: [ - Text( + TextAtom( key, style: const TextStyle(fontSize: 26), ), @@ -38,8 +39,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Device name: '), - Text( + const TextAtom('Device name: '), + TextAtom( softwareInfoEntity?.deviceName.getOrCrash() ?? 'No Info', ), @@ -49,8 +50,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Pubspec yaml version: '), - Text( + const TextAtom('Pubspec yaml version: '), + TextAtom( softwareInfoEntity?.pubspecYamlVersion .getOrCrash() ?? 'No Info', @@ -61,8 +62,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Proto last gen date: '), - Text( + const TextAtom('Proto last gen date: '), + TextAtom( softwareInfoEntity?.protoLastGenDate .getOrCrash() ?? 'No Info', @@ -74,9 +75,9 @@ class SoftwareInfoWidget extends StatelessWidget { title: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text('Dart SDK version: '), + const TextAtom('Dart SDK version: '), Flexible( - child: Text( + child: TextAtom( softwareInfoEntity?.dartSdkVersion .getOrCrash() ?? 'No Info', @@ -88,8 +89,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Comp id: '), - Text( + const TextAtom('Comp id: '), + TextAtom( softwareInfoEntity?.compId.getOrCrash() ?? 'No Info', ), @@ -99,8 +100,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Comp uuid: '), - Text( + const TextAtom('Comp uuid: '), + TextAtom( softwareInfoEntity?.compUuid.getOrCrash() ?? 'No Info', ), @@ -110,8 +111,8 @@ class SoftwareInfoWidget extends StatelessWidget { ListTile( title: Row( children: [ - const Text('Comp os: '), - Text( + const TextAtom('Comp os: '), + TextAtom( softwareInfoEntity?.compOs.getOrCrash() ?? 'No Info', ), diff --git a/lib/presentation/pages/splash/splash_page.dart b/lib/presentation/pages/splash/splash_page.dart index 2cf2dc74f..8ddf24d4c 100644 --- a/lib/presentation/pages/splash/splash_page.dart +++ b/lib/presentation/pages/splash/splash_page.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; @@ -36,7 +37,7 @@ class _PageWidget extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( body: Center( - child: Image.asset( + child: ImageAtom( 'assets/cbj_logo.png', ), ), diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart index 60ea8d921..dcfb17caf 100644 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart +++ b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart'; import 'package:flutter/material.dart'; @@ -23,7 +24,7 @@ class WhereToLoginPageMinimalPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepPurpleAccent[200]!.withOpacity(0.6), - title: const Text('Choose type of login'), + title: const TextAtom('Choose type of login'), ), body: Column( children: [ @@ -37,7 +38,7 @@ class WhereToLoginPageMinimalPage extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'What would you like to do', style: TextStyle( fontSize: 25, @@ -74,7 +75,7 @@ class WhereToLoginPageMinimalPage extends StatelessWidget { const SizedBox( width: 20, ), - Text( + TextAtom( 'Create Your Home', style: TextStyle( fontSize: 25, @@ -113,7 +114,7 @@ class WhereToLoginPageMinimalPage extends StatelessWidget { const SizedBox( width: 20, ), - Text( + TextAtom( 'Join Existing Home', style: TextStyle( fontSize: 25, @@ -131,7 +132,7 @@ class WhereToLoginPageMinimalPage extends StatelessWidget { width: double.infinity, color: Colors.black87, child: const Center( - child: Text( + child: TextAtom( 'Homes you have add', style: TextStyle(fontSize: 20), ), diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart index b75e8b371..2ac570874 100644 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart +++ b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart @@ -1,4 +1,5 @@ import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; class ErrorHomeCard extends StatelessWidget { @@ -17,7 +18,7 @@ class ErrorHomeCard extends StatelessWidget { padding: const EdgeInsets.all(4), child: Column( children: [ - Text( + TextAtom( 'Invalid user, please, contact support', style: Theme.of(context) .primaryTextTheme @@ -25,11 +26,11 @@ class ErrorHomeCard extends StatelessWidget { .copyWith(fontSize: 18), ), const SizedBox(height: 2), - Text( + TextAtom( 'Details for nerds:', style: Theme.of(context).primaryTextTheme.bodyMedium, ), - Text( + TextAtom( home!.failureOption.fold(() => '', (f) => f.toString()), style: Theme.of(context).primaryTextTheme.bodyMedium, ), diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart index 380bb48cb..149f6f5b1 100644 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart +++ b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart @@ -2,6 +2,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -20,17 +21,17 @@ class HomeCardWidget extends StatelessWidget { return BlocBuilder( builder: (context, state) { state.map( - initial: (_) => const Text('initial'), - loadInProgress: (_) => const Text('loadInProgress'), - loadSuccess: (_) => const Text('loadInSuccess'), + initial: (_) => const TextAtom('initial'), + loadInProgress: (_) => const TextAtom('loadInProgress'), + loadSuccess: (_) => const TextAtom('loadInSuccess'), enterHome: (_) { context.router.replace(const HomeRoute()); }, - loadFailure: (_) => const Text('loadFailure'), + loadFailure: (_) => const TextAtom('loadFailure'), loadFailureEnteringHome: (_) => FlushbarHelper.createError( message: "Can't enter this home", ), - error: (_) => const Text('error'), + error: (_) => const TextAtom('error'), ); return TextButton( onPressed: () { @@ -59,7 +60,7 @@ class HomeCardWidget extends StatelessWidget { title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( + TextAtom( home!.name!.getOrCrash()!, style: TextStyle( color: Theme.of(context).textTheme.bodyLarge!.color, diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart index 22e5f324b..d49a34f24 100644 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart +++ b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart @@ -1,6 +1,7 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart'; import 'package:flutter/material.dart'; @@ -9,9 +10,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class UserHomesListWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - final double sizeBoxWidth = screenSize.width * 0.25; - return BlocBuilder( builder: (context, state) { return Expanded( @@ -38,19 +36,19 @@ class UserHomesListWidget extends StatelessWidget { ); }, loadFailure: (state) { - return const Text('Load Failure'); + return const TextAtom('Load Failure'); }, error: (state) { - return const Text('Error'); + return const TextAtom('Error'); }, enterHome: (e) { - return const Text('Entering Home'); + return const TextAtom('Entering Home'); }, loadFailureEnteringHome: (f) { FlushbarHelper.createError( message: "Can't enter this home", ); - return const Text('Failure'); + return const TextAtom('Failure'); }, ), ); diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart index 8f157de96..a4a0025e3 100644 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart +++ b/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart @@ -1,4 +1,5 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -16,7 +17,7 @@ class WhereToLoginPageOffline extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Choose type of login'), + title: const TextAtom('Choose type of login'), ), backgroundColor: Colors.deepPurpleAccent[200]!.withOpacity(0.6), body: Column( @@ -31,7 +32,7 @@ class WhereToLoginPageOffline extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(10)), ), alignment: Alignment.center, - child: Text( + child: TextAtom( 'What would you like to do', style: TextStyle( fontSize: 25, @@ -68,7 +69,7 @@ class WhereToLoginPageOffline extends StatelessWidget { const SizedBox( width: 20, ), - Text( + TextAtom( 'Open Demo', style: TextStyle( fontSize: 25, @@ -110,7 +111,7 @@ class WhereToLoginPageOffline extends StatelessWidget { const SizedBox( width: 20, ), - Text( + TextAtom( 'Work Only On WiFi', style: TextStyle( fontSize: 25, From 71cfc79ec6223f1be4ba66cf5d77d7bc6260ac54 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Thu, 30 Nov 2023 20:03:43 +0200 Subject: [PATCH 08/15] Started removing blocs --- .../hub_in_network/hub_in_network_bloc.dart | 125 ------ .../hub_in_network/hub_in_network_event.dart | 22 - .../hub_in_network/hub_in_network_state.dart | 23 - .../manage_wifi/manage_wifi_bloc.dart | 89 ---- .../manage_wifi/manage_wifi_event.dart | 14 - .../manage_wifi/manage_wifi_state.dart | 19 - lib/presentation/atoms/atoms.dart | 1 + .../circular_progress_indicator_atom.dart | 13 + .../molecules/loading_page_molecule.dart | 17 + .../connect_to_home_wifi_page.dart | 9 +- .../widgets/connect_to_home_wifi_widget.dart | 306 +++++++------ .../connect_to_hub/connect_to_hub_page.dart | 24 +- .../widgets/cbj_hub_in_network_widget.dart | 410 +++++++++--------- .../pages/splash/splash_page.dart | 43 +- 14 files changed, 433 insertions(+), 682 deletions(-) delete mode 100644 lib/application/hub_in_network/hub_in_network_bloc.dart delete mode 100644 lib/application/hub_in_network/hub_in_network_event.dart delete mode 100644 lib/application/hub_in_network/hub_in_network_state.dart delete mode 100644 lib/application/manage_wifi/manage_wifi_bloc.dart delete mode 100644 lib/application/manage_wifi/manage_wifi_event.dart delete mode 100644 lib/application/manage_wifi/manage_wifi_state.dart create mode 100644 lib/presentation/atoms/circular_progress_indicator_atom.dart create mode 100644 lib/presentation/molecules/loading_page_molecule.dart diff --git a/lib/application/hub_in_network/hub_in_network_bloc.dart b/lib/application/hub_in_network/hub_in_network_bloc.dart deleted file mode 100644 index c1b1073ad..000000000 --- a/lib/application/hub_in_network/hub_in_network_bloc.dart +++ /dev/null @@ -1,125 +0,0 @@ -import 'dart:async'; - -import 'package:auto_route/auto_route.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/utils.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; -import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; -import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'hub_in_network_bloc.freezed.dart'; -part 'hub_in_network_event.dart'; -part 'hub_in_network_state.dart'; - -@injectable -class HubInNetworkBloc extends Bloc { - HubInNetworkBloc() : super(HubInNetworkState.initial()) { - on(_initialEvent); - on(_searchHubInNetwork); - on(_openSmartCameraPage); - on(_searchHubUsingAnyIpOnTheNetwork); - on(_isHubIpCheckBoxChangedState); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - BuildContext? context; - static bool loading = false; - - Future _initialEvent( - InitialEvent event, - Emitter emit, - ) async { - context = event.context; - add(const HubInNetworkEvent.searchHubInNetwork()); - } - - Future _searchHubInNetwork( - SearchHubInNetwork event, - Emitter emit, - ) async { - loading = true; - emit(const HubInNetworkState.loadInProgress()); - emit( - await (await IHubConnectionRepository.instance.searchForHub()).fold( - (l) async { - final PhoneHub phoneHub = PhoneHub(); - - final Map smartDevices = - await phoneHub.getAllDevices; - if (smartDevices.isEmpty) { - return HubInNetworkState.loadFailure(l); - } - await IHubConnectionRepository.instance.closeConnection(); - phoneHub.startListen(); - logger.i('All Devices smartDevices $smartDevices'); - context?.router.replace(const HomeRoute()); - return const HubInNetworkState.loadSuccess(); - }, (r) { - context?.router.replace(const HomeRoute()); - return const HubInNetworkState.loadSuccess(); - }), - ); - loading = false; - } - - Future _searchHubUsingAnyIpOnTheNetwork( - SearchHubUsingAnyIpOnTheNetwork event, - Emitter emit, - ) async { - emit(const HubInNetworkState.loadInProgress()); - emit( - (await IHubConnectionRepository.instance.searchForHub( - deviceIpOnTheNetwork: event.ipOnTheNetwork, - isThatTheIpOfTheHub: event.isHubIp, - )) - .fold((l) => HubInNetworkState.loadFailure(l), (r) { - context?.router.replace(const HomeRoute()); - return const HubInNetworkState.loadSuccess(); - }), - ); - } - - Future _isHubIpCheckBoxChangedState( - IsHubIpCheckBoxChangedState event, - Emitter emit, - ) async { - emit(HubInNetworkState.tryIpManually(event.ipOnTheNetwork, event.isHubIp)); - } - - Future _openSmartCameraPage( - OpenSmartCameraPage event, - Emitter emit, - ) async { - if (loading) { - Fluttertoast.showToast( - msg: 'Wait until search completes', - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(event.context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - return; - } - await IHubConnectionRepository.instance.closeConnection(); - - event.context.router.push(const SmartCameraContainerRoute()); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/hub_in_network/hub_in_network_event.dart b/lib/application/hub_in_network/hub_in_network_event.dart deleted file mode 100644 index 6801e02f2..000000000 --- a/lib/application/hub_in_network/hub_in_network_event.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'hub_in_network_bloc.dart'; - -@freezed -class HubInNetworkEvent with _$HubInNetworkEvent { - const factory HubInNetworkEvent.initialEvent(BuildContext context) = - InitialEvent; - - const factory HubInNetworkEvent.searchHubInNetwork() = SearchHubInNetwork; - - const factory HubInNetworkEvent.openSmartCameraPage(BuildContext context) = - OpenSmartCameraPage; - - const factory HubInNetworkEvent.searchHubUsingAnyIpOnTheNetwork( - String ipOnTheNetwork, - bool isHubIp, - ) = SearchHubUsingAnyIpOnTheNetwork; - - const factory HubInNetworkEvent.isHubIpCheckBoxChangedState( - String ipOnTheNetwork, - bool isHubIp, - ) = IsHubIpCheckBoxChangedState; -} diff --git a/lib/application/hub_in_network/hub_in_network_state.dart b/lib/application/hub_in_network/hub_in_network_state.dart deleted file mode 100644 index 9b5f62b68..000000000 --- a/lib/application/hub_in_network/hub_in_network_state.dart +++ /dev/null @@ -1,23 +0,0 @@ -part of 'hub_in_network_bloc.dart'; - -@freezed -class HubInNetworkState with _$HubInNetworkState { - factory HubInNetworkState.initial() = _Initial; - - const factory HubInNetworkState.loadInProgress() = _LoadInProgress; - - const factory HubInNetworkState.loadSuccess() = _loadSuccess; - - const factory HubInNetworkState.loadSuccessSecurityCamera(String address) = - loadSuccessSecurityCamera; - - const factory HubInNetworkState.tryIpManually( - String ipOnTheNetwork, - bool isHubIp, - ) = TryIpManually; - - const factory HubInNetworkState.loadFailure(HubFailures hubFailure) = - _loadFailure; - - const factory HubInNetworkState.lightError() = LightError; -} diff --git a/lib/application/manage_wifi/manage_wifi_bloc.dart b/lib/application/manage_wifi/manage_wifi_bloc.dart deleted file mode 100644 index 8bb3407fa..000000000 --- a/lib/application/manage_wifi/manage_wifi_bloc.dart +++ /dev/null @@ -1,89 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'manage_wifi_bloc.freezed.dart'; -part 'manage_wifi_event.dart'; -part 'manage_wifi_state.dart'; - -@injectable -class ManageWifiBloc extends Bloc { - ManageWifiBloc() : super(ManageWifiState.initial()) { - on(_initialized); - on(_scanForWiFiNetworks); - on(_connectToWiFi); - on(_wifiSsidChanged); - on(_wifiPassChanged); - } - - ManageWiFiName? wifiName; - ManageWiFiPass? wifiPassword; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(ManageWifiState.loading()); - - final Either doesWiFiEnabled = - await IManageNetworkRepository.instance.doesWiFiEnabled(); - - emit( - doesWiFiEnabled.fold((f) => ManageWifiState.wifiIsDisabled(), (r) { - wifiName = r != null ? ManageWiFiName(r) : null; - return ManageWifiState.wifiIsEnabled(r); - }), - ); - } - - Future _scanForWiFiNetworks( - ScanForWiFiNetworks event, - Emitter emit, - ) async { - emit(ManageWifiState.loading()); - // _manageWiFiRepository.scanWiFiNetworks(); - } - - Future _connectToWiFi( - ConnectToWifi event, - Emitter emit, - ) async { - emit(ManageWifiState.loading()); - - final ManageNetworkEntity manageWiFiEntity = ManageNetworkEntity( - name: wifiName, - pass: wifiPassword, - ); - - final Either doesWiFiEnabled = - await IManageNetworkRepository.instance.connectToWiFi(manageWiFiEntity); - - emit( - doesWiFiEnabled.fold( - (f) => ManageWifiState.error(), - (r) => ManageWifiState.loaded(), - ), - ); - } - - Future _wifiSsidChanged( - WifiSsidChanged event, - Emitter emit, - ) async { - wifiName = ManageWiFiName(event.wifiSsidStr); - } - - Future _wifiPassChanged( - WifiPassChanged event, - Emitter emit, - ) async { - wifiPassword = ManageWiFiPass(event.wifiPassStr); - } -} diff --git a/lib/application/manage_wifi/manage_wifi_event.dart b/lib/application/manage_wifi/manage_wifi_event.dart deleted file mode 100644 index bd37f3558..000000000 --- a/lib/application/manage_wifi/manage_wifi_event.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'manage_wifi_bloc.dart'; - -@freezed -class ManageWifiEvent with _$ManageWifiEvent { - factory ManageWifiEvent.connectToWiFi() = ConnectToWifi; - - factory ManageWifiEvent.scanForWiFiNetworks() = ScanForWiFiNetworks; - - factory ManageWifiEvent.wifiSsidChanged(String wifiSsidStr) = WifiSsidChanged; - - factory ManageWifiEvent.wifiPassChanged(String wifiPassStr) = WifiPassChanged; - - factory ManageWifiEvent.initialized() = Initialized; -} diff --git a/lib/application/manage_wifi/manage_wifi_state.dart b/lib/application/manage_wifi/manage_wifi_state.dart deleted file mode 100644 index b51fb2903..000000000 --- a/lib/application/manage_wifi/manage_wifi_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'manage_wifi_bloc.dart'; - -@freezed -class ManageWifiState with _$ManageWifiState { - factory ManageWifiState.initial() = Initial; - - // factory ConnectToHomeWifiState.initialized() => ScanForWiFi; - - factory ManageWifiState.loading() = Loading; - - factory ManageWifiState.wifiIsDisabled() = WifiIsDisabled; - - factory ManageWifiState.wifiIsEnabled(String? currentWiFiName) = - WifiIsEnabled; - - factory ManageWifiState.loaded() = Loaded; - - factory ManageWifiState.error() = Error; -} diff --git a/lib/presentation/atoms/atoms.dart b/lib/presentation/atoms/atoms.dart index 68b7930f4..dc71f42eb 100644 --- a/lib/presentation/atoms/atoms.dart +++ b/lib/presentation/atoms/atoms.dart @@ -1,2 +1,3 @@ +export 'circular_progress_indicator_atom.dart'; export 'image_atom.dart'; export 'text_atom.dart'; diff --git a/lib/presentation/atoms/circular_progress_indicator_atom.dart b/lib/presentation/atoms/circular_progress_indicator_atom.dart new file mode 100644 index 000000000..e7ec286ca --- /dev/null +++ b/lib/presentation/atoms/circular_progress_indicator_atom.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class CircularProgressIndicatorAtom extends StatelessWidget { + const CircularProgressIndicatorAtom({super.key}); + + @override + Widget build(BuildContext context) { + return Container( + alignment: Alignment.center, + child: const CircularProgressIndicator(), + ); + } +} diff --git a/lib/presentation/molecules/loading_page_molecule.dart b/lib/presentation/molecules/loading_page_molecule.dart new file mode 100644 index 000000000..3c59fba7f --- /dev/null +++ b/lib/presentation/molecules/loading_page_molecule.dart @@ -0,0 +1,17 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:flutter/material.dart'; + +class LoadingPageMolecule extends StatelessWidget { + const LoadingPageMolecule({super.key}); + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final ColorScheme colorScheme = themeData.colorScheme; + + return Scaffold( + backgroundColor: colorScheme.background, + body: const CircularProgressIndicatorAtom(), + ); + } +} diff --git a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart index 23c024c60..d9aeae481 100644 --- a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/manage_wifi/manage_wifi_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -71,11 +68,7 @@ class ConnectToHomeWifiPage extends StatelessWidget { height: 20, ), Expanded( - child: BlocProvider( - create: (context) => - getIt()..add(ManageWifiEvent.initialized()), - child: ConnectToHomeWiFiWidget(), - ), + child: ConnectToHomeWiFiWidget(), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart index 552b58dbb..29235f75f 100644 --- a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/widgets/connect_to_home_wifi_widget.dart @@ -1,152 +1,176 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/manage_wifi/manage_wifi_bloc.dart'; +import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; +import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -class ConnectToHomeWiFiWidget extends StatelessWidget { +class ConnectToHomeWiFiWidget extends StatefulWidget { + @override + State createState() => + _ConnectToHomeWiFiWidgetState(); +} + +class _ConnectToHomeWiFiWidgetState extends State { + ConnectToHomeWiFiState state = ConnectToHomeWiFiState.loading; + ManageWiFiName? wifiName; + ManageWiFiPass? wifiPassword; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + final dartz.Either doesWiFiEnabled = + await IManageNetworkRepository.instance.doesWiFiEnabled(); + + doesWiFiEnabled.fold((f) { + setState(() { + state = ConnectToHomeWiFiState.wifiIsDisabled; + }); + }, (r) { + wifiName = r != null ? ManageWiFiName(r) : null; + setState(() { + state = ConnectToHomeWiFiState.wifiIsEnabled; + }); + }); + } + + Future _connectToWiFi() async { + final ManageNetworkEntity manageWiFiEntity = ManageNetworkEntity( + name: wifiName, + pass: wifiPassword, + ); + + final dartz.Either doesWiFiEnabled = + await IManageNetworkRepository.instance.connectToWiFi(manageWiFiEntity); + + final ConnectToHomeWiFiState tempState = doesWiFiEnabled.fold( + (f) => ConnectToHomeWiFiState.error, + (r) => ConnectToHomeWiFiState.loaded, + ); + + setState(() { + state = tempState; + }); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return SingleChildScrollView( - child: Column( - children: [ - state.map( - initial: (value) { - return const TextAtom('Initial'); - }, - loading: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); - }, - loaded: (l) { - context.router.replace(const OpenAccessPointRoute()); - return const TextAtom('Loaded'); - }, - error: (e) { - return const TextAtom('Failure'); - }, - wifiIsEnabled: (WifiIsEnabled wifiIsEnabled) { - return Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(horizontal: 50), - child: const TextAtom( - 'Smart Devices need your home WiFi name and ' - 'password in order to connect.', - style: TextStyle(fontSize: 17), - ), - ), - const SizedBox( - height: 30, - ), - SizedBox( - width: 300, - child: TextFormField( - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.wifi, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'WiFi Name', - labelStyle: TextStyle( - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - context - .read() - .add(ManageWifiEvent.wifiSsidChanged(value)); - }, - initialValue: wifiIsEnabled.currentWiFiName, - ), - ), - const SizedBox( - height: 15, - ), - SizedBox( - width: 300, - child: TextFormField( - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.vpn_key, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'Password', - labelStyle: TextStyle( - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - context - .read() - .add(ManageWifiEvent.wifiPassChanged(value)); - }, - ), - ), - const SizedBox( - height: 20, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.pinkAccent, - ), - ), - onPressed: () { - context - .read() - .add(ManageWifiEvent.connectToWiFi()); - }, - child: TextAtom( - 'Connect to WiFi', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], - ); - }, - wifiIsDisabled: (WifiIsDisabled value) { - return const TextAtom('WiFi is disabled'); - }, + if (state == ConnectToHomeWiFiState.loaded) { + context.router.replace(const OpenAccessPointRoute()); + return const TextAtom('Loaded'); + } + + if (state == ConnectToHomeWiFiState.error) { + return const TextAtom('Failure'); + } + + if (state == ConnectToHomeWiFiState.wifiIsEnabled) { + return Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(horizontal: 50), + child: const TextAtom( + 'Smart Devices need your home WiFi name and ' + 'password in order to connect.', + style: TextStyle(fontSize: 17), + ), + ), + const SizedBox( + height: 30, + ), + SizedBox( + width: 300, + child: TextFormField( + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, ), - // TextButton( - // style: ButtonStyle( - // backgroundColor: MaterialStateProperty.all( - // Colors.greenAccent, - // ), - // ), - // onPressed: () { - // context.router.replace(const OpenAccessPointRoute()); - // }, - // child: const TextAtom('Next'), - // ), - ], + decoration: InputDecoration( + filled: true, + fillColor: Colors.greenAccent.withOpacity(0.3), + prefixIcon: Icon( + Icons.wifi, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + labelText: 'WiFi Name', + labelStyle: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + autocorrect: false, + onChanged: (value) { + wifiName = ManageWiFiName(value); + }, + initialValue: wifiName == null ? '' : wifiName!.getOrCrash(), + ), ), - ); - }, - ); + const SizedBox( + height: 15, + ), + SizedBox( + width: 300, + child: TextFormField( + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + decoration: InputDecoration( + filled: true, + fillColor: Colors.greenAccent.withOpacity(0.3), + prefixIcon: Icon( + Icons.vpn_key, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + labelText: 'Password', + labelStyle: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + autocorrect: false, + onChanged: (value) { + wifiPassword = ManageWiFiPass(value); + }, + ), + ), + const SizedBox( + height: 20, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.pinkAccent, + ), + ), + onPressed: _connectToWiFi, + child: TextAtom( + 'Connect to WiFi', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ], + ); + } + + if (state == ConnectToHomeWiFiState.wifiIsDisabled) { + return const TextAtom('WiFi is disabled'); + } + + return const CircularProgressIndicatorAtom(); } } + +enum ConnectToHomeWiFiState { + loading, + loaded, + error, + wifiIsEnabled, + wifiIsDisabled, + ; +} diff --git a/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart b/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart index f0e534400..1ac15da69 100644 --- a/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart +++ b/lib/presentation/pages/connect_to_hub/connect_to_hub_page.dart @@ -1,12 +1,10 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/hub_in_network/hub_in_network_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; +import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -49,7 +47,7 @@ class ConnectToHubPage extends StatelessWidget { Container( alignment: Alignment.center, child: const TextAtom( - ' Connect to Hub', + 'Connect to Hub', textAlign: TextAlign.center, style: TextStyle( fontSize: 35, @@ -92,18 +90,9 @@ class ConnectToHubPage extends StatelessWidget { ], ), ), - Expanded( + const Expanded( child: Center( - child: BlocProvider( - create: (BuildContext context) => - getIt() - ..add( - HubInNetworkEvent.initialEvent( - context, - ), - ), - child: CbjHubInNetworkWidget(), - ), + child: CbjHubInNetworkWidget(), ), ), ], @@ -177,9 +166,8 @@ class ConnectToHubPage extends StatelessWidget { const SizedBox(height: 20), GestureDetector( onTap: () { - getIt().add( - HubInNetworkEvent.openSmartCameraPage(context), - ); + context.router.push(const SmartCameraContainerRoute()); + IHubConnectionRepository.instance.closeConnection(); }, child: Container( margin: const EdgeInsets.symmetric(horizontal: 30), diff --git a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart index f21a0268a..24efac0c2 100644 --- a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart +++ b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart @@ -1,222 +1,230 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/hub_in_network/hub_in_network_bloc.dart'; import 'package:cybear_jinni/domain/hub/hub_failures.dart'; +import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; -class CbjHubInNetworkWidget extends StatelessWidget { +class CbjHubInNetworkWidget extends StatefulWidget { + const CbjHubInNetworkWidget({super.key}); + + @override + State createState() => _CbjHubInNetworkWidgetState(); +} + +class _CbjHubInNetworkWidgetState extends State { + FindingHubState state = FindingHubState.loading; + bool loading = false; + String? ipOnTheNetwork; + HubFailures? hubFailure; + + @override + void initState() { + super.initState(); + _searchHub(); + } + + Future _searchHub() async { + setState(() { + state = FindingHubState.loading; + }); + if (loading) { + return; + } + + loading = true; + final dartz.Either eitherHub = + await IHubConnectionRepository.instance.searchForHub(); + eitherHub.fold((l) async { + await IHubConnectionRepository.instance.closeConnection(); + + if (!mounted) { + return null; + } + setState(() { + state = FindingHubState.tryIpManually; + }); + }, (r) { + context.router.replace(const HomeRoute()); + }); + loading = false; + } + + Future _searchHubUsingAnyIpOnTheNetwork({ + required String? ipOnTheNetwork, + }) async { + final dartz.Either searchHub = + await IHubConnectionRepository.instance.searchForHub( + deviceIpOnTheNetwork: ipOnTheNetwork, + isThatTheIpOfTheHub: true, + ); + searchHub.fold((l) { + setState(() { + state = FindingHubState.loadFailure; + }); + }, (r) { + context.router.replace(const HomeRoute()); + }); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => const TextAtom('Go'), - loadInProgress: (_) => const SizedBox( - height: 70, - width: 70, - child: CircularProgressIndicator(), - ), - loadSuccess: (_) => const TextAtom('Found hub'), - loadSuccessSecurityCamera: (loadSuccessSecurityCamera value) { - context.router.push( - VideoStreamOutputContainerRoute(streamAddress: value.address), - ); + if (loading || state == FindingHubState.loading) { + return const SizedBox( + height: 70, + width: 70, + child: CircularProgressIndicator(), + ); + } - return const TextAtom('Found Smart Camera'); - }, - loadFailure: (failure) { - if (failure.hubFailure == - const HubFailures.cantFindHubInNetwork()) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const TextAtom( - "Can't find a Hub in your network.", - style: TextStyle(color: Colors.white), - ), - const SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - style: TextButton.styleFrom( - backgroundColor: HexColor('#734d99'), - foregroundColor: Colors.white, - ), - onPressed: () { - context.read().add( - const HubInNetworkEvent.searchHubInNetwork(), - ); - }, - child: const TextAtom('Retry'), - ), - const SizedBox( - width: 40, - ), - TextButton( - style: TextButton.styleFrom( - backgroundColor: HexColor('#734d99'), - foregroundColor: Colors.white, - ), - onPressed: () { - context.read().add( - const HubInNetworkEvent - .isHubIpCheckBoxChangedState( - '', - false, - ), - ); - }, - child: const TextAtom('Retry Manually'), - ), - ], - ), - ], - ); - } else if (failure.hubFailure == - const HubFailures.automaticHubSearchNotSupportedOnWeb()) { - return const TextAtom( - 'Automatic search does not supported on the web.', - ); - } else if (failure.hubFailure == - const HubFailures - .findingHubWhenConnectedToEthernetCableIsNotSupported()) { - context.read().add( - const HubInNetworkEvent.isHubIpCheckBoxChangedState( - '', - false, - ), - ); - } - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const TextAtom("Unexpected error"), - const SizedBox( - height: 20, - ), - TextButton( - style: TextButton.styleFrom( - backgroundColor: Colors.white.withOpacity(0.8), - ), - onPressed: () { - context.read().add( - const HubInNetworkEvent.searchHubInNetwork(), - ); - }, - child: const TextAtom('Retry'), - ), - ], - ); - }, - lightError: (_) => const TextAtom('Got Error'), - tryIpManually: (TryIpManually tryIpManuallyValue) { - String anyIpOnTheNetwork = tryIpManuallyValue.ipOnTheNetwork; + if (state == FindingHubState.tryIpManually) { + String? anyIpOnTheNetwork = ipOnTheNetwork; - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const TextAtom( - "Automatic search currently supported only on WiFi.\n" - "Please enter manually any IP on the network or connect the device to WiFi and try again.", - style: TextStyle( - fontSize: 18, - color: Colors.white, - ), - ), - const SizedBox(height: 40), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 50), - child: TextFormField( - style: const TextStyle(color: Colors.white), - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.ethernet, - color: Colors.white, - ), - labelText: 'Any IP on the network', - labelStyle: TextStyle(color: Colors.white), - ), - autocorrect: false, - initialValue: anyIpOnTheNetwork, - onChanged: (value) { - anyIpOnTheNetwork = value; - }, - ), + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const TextAtom( + "Can't find CBJ Hub in your network.\n" + "Please retry again", + style: TextStyle( + fontSize: 18, + color: Colors.white, + ), + ), + const SizedBox(height: 20), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: TextFormField( + style: const TextStyle(color: Colors.white), + decoration: const InputDecoration( + prefixIcon: FaIcon( + FontAwesomeIcons.ethernet, + color: Colors.white, ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const TextAtom( - 'Is Hub IP', - style: TextStyle( - fontSize: 17, - color: Colors.white, - ), - ), - Checkbox( - value: tryIpManuallyValue.isHubIp, - onChanged: (bool? value) { - context.read().add( - HubInNetworkEvent.isHubIpCheckBoxChangedState( - anyIpOnTheNetwork, - value!, - ), - ); - }, + labelText: 'Hub IP', + labelStyle: TextStyle(color: Colors.white), + ), + autocorrect: false, + initialValue: anyIpOnTheNetwork, + onChanged: (value) { + anyIpOnTheNetwork = value; + }, + ), + ), + TextButton( + onPressed: () { + if (anyIpOnTheNetwork == '') { + showDialog( + context: context, + builder: (_) => const AlertDialog( + title: TextAtom( + 'Please insert valid IP before clicking the Search Button', ), - ], - ), - const SizedBox(height: 20), - TextButton( - onPressed: () { - if (anyIpOnTheNetwork == '') { - showDialog( - context: context, - builder: (_) => const AlertDialog( - title: TextAtom( - 'Please insert valid IP before clicking the Search Button', - ), - ), - ); - return; - } - context.read().add( - HubInNetworkEvent.searchHubUsingAnyIpOnTheNetwork( - anyIpOnTheNetwork, - tryIpManuallyValue.isHubIp, - ), - ); - }, - child: const TextAtom( - 'Search', - style: TextStyle(color: Colors.white), ), + ); + return; + } + _searchHubUsingAnyIpOnTheNetwork( + ipOnTheNetwork: anyIpOnTheNetwork); + }, + child: const TextAtom( + 'Search', + style: TextStyle(color: Colors.white), + ), + ), + TextButton( + style: TextButton.styleFrom( + backgroundColor: HexColor('#734d99'), + foregroundColor: Colors.white, + ), + onPressed: _searchHub, + child: const TextAtom('Retry'), + ), + const SizedBox(height: 10), + ], + ); + } + + if (hubFailure == const HubFailures.cantFindHubInNetwork()) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const TextAtom( + "Can't find a Hub in your network.", + style: TextStyle(color: Colors.white), + ), + const SizedBox( + height: 20, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton( + style: TextButton.styleFrom( + backgroundColor: HexColor('#734d99'), + foregroundColor: Colors.white, ), - const SizedBox(height: 40), - TextButton( - style: TextButton.styleFrom( - backgroundColor: HexColor('#734d99'), - foregroundColor: Colors.white, - ), - onPressed: () { - context.read().add( - const HubInNetworkEvent.searchHubInNetwork(), - ); - }, - child: const TextAtom('Retry'), + onPressed: () { + _searchHub(); + }, + child: const TextAtom('Retry'), + ), + const SizedBox( + width: 40, + ), + TextButton( + style: TextButton.styleFrom( + backgroundColor: HexColor('#734d99'), + foregroundColor: Colors.white, ), - ], - ); + onPressed: () { + ipOnTheNetwork = ''; + }, + child: const TextAtom('Retry Manually'), + ), + ], + ), + ], + ); + } else if (hubFailure == + const HubFailures.automaticHubSearchNotSupportedOnWeb()) { + return const TextAtom( + 'Automatic search does not supported on the web.', + ); + } else if (hubFailure == + const HubFailures + .findingHubWhenConnectedToEthernetCableIsNotSupported()) { + ipOnTheNetwork = ''; + } + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const TextAtom("Unexpected error"), + const SizedBox( + height: 20, + ), + TextButton( + style: TextButton.styleFrom( + backgroundColor: Colors.white.withOpacity(0.8), + ), + onPressed: () { + _searchHub(); }, - ); - }, + child: const TextAtom('Retry'), + ), + ], ); } } + +enum FindingHubState { + loading, + loadSuccessSecurityCamera, + loadFailure, + lightError, + tryIpManually, + ; +} diff --git a/lib/presentation/pages/splash/splash_page.dart b/lib/presentation/pages/splash/splash_page.dart index 8ddf24d4c..ba629f497 100644 --- a/lib/presentation/pages/splash/splash_page.dart +++ b/lib/presentation/pages/splash/splash_page.dart @@ -1,41 +1,40 @@ import 'dart:io'; import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; +import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() -class SplashPage extends StatelessWidget { +class SplashPage extends StatefulWidget { @override - Widget build(BuildContext context) { - return BlocListener( - listener: (context, state) { - state.map( - initial: (_) {}, - authenticated: (_) async { - return context.router.replace(const HomeRoute()); - }, - unauthenticated: (_) async { - if (kIsWeb || Platform.isLinux || Platform.isWindows) { - return context.router.replace(const ConnectToHubRoute()); - } - return context.router.replace(const IntroductionRouteRoute()); - }, - ); + State createState() => _SplashPageState(); +} + +class _SplashPageState extends State { + @override + void initState() { + super.initState(); + _navigate(); + } + + Future _navigate() async { + (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( + (l) { + if (kIsWeb || Platform.isLinux || Platform.isWindows) { + return context.router.replace(const ConnectToHubRoute()); + } + return context.router.replace(const IntroductionRouteRoute()); }, - child: _PageWidget(), + (r) => context.router.replace(const HomeRoute()), ); } -} -class _PageWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( + return const Scaffold( body: Center( child: ImageAtom( 'assets/cbj_logo.png', From 92d859c89b2449da1ef7611bb428209713160abb Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Thu, 30 Nov 2023 23:57:00 +0200 Subject: [PATCH 09/15] Switched bloc to stateful. fix lint --- .../boilers_actor/boilers_actor_bloc.dart | 12 +- .../configure_new_cbj_comp_bloc.dart | 16 +- .../device_actor/device_actor_bloc.dart | 7 +- .../esphome_sign_in_form_bloc.dart | 59 -- .../esphome_sign_in_form_event.dart | 10 - .../esphome_sign_in_form_state.dart | 18 - .../ewelink_sign_in_form_bloc.dart | 72 --- .../ewelink_sign_in_form_event.dart | 13 - .../ewelink_sign_in_form_state.dart | 20 - .../lifx_sign_in_form_bloc.dart | 56 -- .../lifx_sign_in_form_event.dart | 10 - .../lifx_sign_in_form_state.dart | 18 - .../light_toggle/light_toggle_bloc.dart | 8 +- .../lights_actor/lights_actor_bloc.dart | 9 +- .../lights_watcher/lights_watcher_bloc.dart | 5 +- .../more_connections_options_bloc.dart | 2 +- .../plus_button_settings_bloc.dart | 41 -- .../plus_button_settings_event.dart | 9 - .../plus_button_settings_state.dart | 12 - .../printers_actor/printers_actor_bloc.dart | 29 +- .../printers_watcher_bloc.dart | 13 +- .../remote_pipes/remote_pipes_bloc.dart | 4 +- .../security_camera_actor_event.dart | 3 +- .../smart_computers_actor_bloc.dart | 16 +- .../smart_computer_watcher_bloc.dart | 14 +- .../smart_plug_toggle_bloc.dart | 8 +- .../smart_plugs_actor_bloc.dart | 12 +- .../smart_plugs_watcher_bloc.dart | 14 +- .../software_info/software_info_bloc.dart | 74 --- .../software_info/software_info_event.dart | 8 - .../software_info/software_info_state.dart | 10 - .../switch_toggle/switch_toggle_bloc.dart | 3 +- .../switches_watcher_bloc.dart | 13 +- .../tuya_sign_in_form_bloc.dart | 144 ----- .../tuya_sign_in_form_event.dart | 26 - .../tuya_sign_in_form_state.dart | 30 - lib/application/vendors/vendors_bloc.dart | 36 -- lib/application/vendors/vendors_event.dart | 6 - lib/application/vendors/vendors_state.dart | 19 - .../xiaomi_mi_sign_in_form_bloc.dart | 72 --- .../xiaomi_mi_sign_in_form_event.dart | 13 - .../xiaomi_mi_sign_in_form_state.dart | 20 - .../cbj_comp/cbj_comp_value_objects.dart | 2 +- lib/domain/hub/hub_entity.dart | 38 -- lib/domain/hub/hub_errors.dart | 16 - lib/domain/hub/hub_failures.dart | 30 - lib/domain/hub/hub_validators.dart | 14 - lib/domain/hub/hub_value_objects.dart | 89 --- .../hub/i_hub_connection_repository.dart | 6 +- .../add_user_to_home_reposityory.dart | 7 +- .../cbj_app_server/cbj_app_server_d.dart | 2 +- .../create_home/create_home_repository.dart | 4 +- .../devices/device/device_repository.dart | 5 +- .../hub_auth_facade/hub_auth_facade.dart | 5 - lib/infrastructure/hub_client/hub_client.dart | 114 ---- .../hub_client/hub_client_demo.dart | 603 ------------------ .../hub_client/hub_connection_repository.dart | 12 +- lib/infrastructure/hub_client/hub_dtos.dart | 53 -- .../hub_client/hub_requests_routing.dart | 12 +- lib/infrastructure/mqtt/mqtt.dart | 12 +- lib/infrastructure/phone_hub/phone_hub.dart | 10 +- .../remote_pipes/remote_pipes_repository.dart | 2 +- lib/infrastructure/room/room_repository.dart | 2 +- .../security_bear_connection_repository.dart | 4 - .../software_info_repository.dart | 2 +- lib/infrastructure/user/user_repository.dart | 14 +- lib/infrastructure/vendors/vendor_helper.dart | 62 -- .../vendors/vendors_repository.dart | 288 --------- lib/main.dart | 26 - lib/presentation/core/notifications.dart | 31 +- .../add_routine/add_routine_page.dart | 2 +- .../add_new_devices/add_new_cbj_devices.dart | 1 - .../choose_device_vendor_to_add_page.dart | 9 +- .../widgets/vendor_widget.dart | 12 - .../widgets/vendors_list.dart | 69 +- .../computer_connection_check_page.dart | 1 - .../configure_new_cbj_comp_page.dart | 1 - .../configure_new_cbj_comp_widget.dart | 2 +- .../connect_to_home_wifi_page.dart | 1 - .../open_access_pointi_page.dart | 1 - .../widgets/open_access_point_widget.dart | 5 +- .../scan_for_new_cbj_comps_page.dart | 1 - .../scan_for_new_cbj_comps_widget.dart | 4 +- .../widgets/add_user_to_home_widget.dart | 14 +- .../add_esphome_vendor_page.dart | 8 +- .../widgets/esphome_sign_in_form.dart | 203 +++--- .../add_ewelink_vendor_page.dart | 8 +- .../widgets/ewelink_sign_in_form.dart | 259 ++++---- .../add_jinvoo_smart_vendor_page.dart | 29 - .../widgets/jinvoo_smart_sign_in_form.dart | 243 ------- .../add_lifx_vendor/add_lifx_vendor_page.dart | 10 +- .../widgets/lifx_sign_in_form.dart | 236 +++---- .../add_smart_life_vendor_page.dart | 29 - .../widgets/smart_life_sign_in_form.dart | 244 ------- .../add_tuya_vendor/add_tuya_vendor_page.dart | 29 - .../widgets/tuya_sign_in_form.dart | 243 ------- .../add_xiaomi_mi_vendor_page.dart | 29 - .../widgets/xiaomi_mi_sign_in_form.dart | 175 ----- .../change_room_for_devices_page.dart | 1 - .../widgets/cbj_hub_in_network_widget.dart | 16 +- .../widgets/connect_to_hub_more_widget.dart | 2 +- .../widgets/create_home_widget.dart | 2 +- .../blinds_in_the_room_page.dart | 2 - .../blinds_in_the_room_widget.dart | 2 +- .../blinds/settings_page_of_blinds.dart | 1 - .../blinds/smart_blind_widget.dart | 2 +- .../blinds/widgets/rooms_blinds_widget.dart | 17 +- .../boilers_in_the_room_page.dart | 2 - .../boilers_in_the_room_widget.dart | 2 +- .../boilers/settings_page_of_boilers.dart | 1 - .../boilers/smart_boiler_widget.dart | 2 +- .../boilers/widgets/room_boilers.dart | 2 +- .../boilers/widgets/rooms_boilers_widget.dart | 18 +- .../lights_in_the_room_page.dart | 2 - .../lights_in_the_room_widget.dart | 2 +- .../lights/settings_page_of_lights.dart | 1 - .../lights/smart_lighte_widget.dart | 2 +- .../widgets/lights_widgets/light_widget.dart | 2 +- .../lights/widgets/room_lights.dart | 2 +- .../lights/widgets/rooms_lights_widget.dart | 19 +- .../printers/printer_widget.dart | 6 +- .../printers_in_the_room_page.dart | 2 - .../printers_in_the_room_widget.dart | 2 +- .../printers/settings_page_of_printers.dart | 1 - .../printers/widgets/printer_widget.dart | 7 +- .../printers/widgets/room_printers.dart | 2 +- .../widgets/rooms_printers_widget.dart | 17 +- .../settings_page_of_smart_computers.dart | 1 - .../smart_computer_widget.dart | 6 +- .../smart_computers_in_the_room_page.dart | 2 - .../smart_computers_in_the_room_widget.dart | 2 +- .../widgets/room_smart_computers.dart | 2 +- .../widgets/rooms_smart_computers_widget.dart | 18 +- .../settings_page_of_smart_plug.dart | 1 - .../smart_plugs/smart_plug_widget.dart | 2 +- .../smart_plugs_in_the_room_page.dart | 2 - .../smart_plugs_in_the_room_widget.dart | 2 +- .../smart_plugs/widgets/room_smart_plugs.dart | 2 +- .../widgets/rooms_smart_plugs_widget.dart | 17 +- .../smart_tv/settings_page_of_smart_tvs.dart | 25 +- .../smart_tv/smart_tv_widget.dart | 6 +- .../smart_computers_in_the_room_page.dart | 2 - .../smart_computers_in_the_room_widget.dart | 2 +- .../smart_tv/widgets/open_url_widget.dart | 6 +- .../smart_tv/widgets/room_smart_tvs.dart | 2 +- .../widgets/rooms_smart_tvs_widget.dart | 18 +- .../smart_tv/widgets/smart_tv_widget.dart | 24 +- .../switches/settings_page_of_switches.dart | 1 - .../switches/smart_switch_widget.dart | 2 +- .../switches_in_the_room_page.dart | 2 - .../switches_in_the_room_widget.dart | 2 +- .../switches/widgets/room_switches.dart | 2 +- .../widgets/rooms_switches_widget.dart | 18 +- .../bottom_navigation_bar_home_page.dart | 4 +- .../pages/home_page/home_page.dart | 2 - .../left_navigation_drawer_home_page.dart | 192 ------ .../add_bindings/add_bindings_page.dart | 1 - .../tabs/bindings_tab/bindings_page.dart | 2 +- .../widgets/scenes_in_folders_l.dart | 2 +- .../security_cameras_in_the_room_block.dart | 9 +- .../rooms_widgets/rom_widget.dart | 4 +- .../settings_page_of_smart_devices.dart | 1 - .../smart_devices_by_rooms.dart | 6 +- .../introduction_screen_body.dart | 2 +- .../widgets/join_home_by_id_widget.dart | 10 +- .../widgets/manage_users_widget.dart | 2 +- .../pages/plus_button/plus_button.dart | 11 +- .../widgets/plus_button_wighet.dart | 523 +++++++-------- lib/presentation/pages/routes/app_router.dart | 8 +- .../pages/scenes/scenes_page.dart | 2 +- .../scenes/widgets/folder_of_scenes.dart | 4 +- .../shared_widgets/add_new_devie_widget.dart | 6 +- .../shared_widgets/top_navigation_bar.dart | 11 +- .../pages/sign_in_page/sign_in_page.dart | 23 - .../widgets/sign_in_form_widget.dart | 169 ----- .../software_info/software_info_page.dart | 74 +-- .../widgets/software_info_widget.dart | 276 ++++---- .../where_to_login_page_minimal_page.dart | 175 ----- .../widgets/error_home_card_widget.dart | 42 -- .../widgets/home_card_widget.dart | 78 --- .../widgets/user_homes_list_widget.dart | 58 -- .../where_to_login_page_offline.dart | 137 ---- pubspec.yaml | 4 +- 183 files changed, 1042 insertions(+), 5421 deletions(-) delete mode 100644 lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart delete mode 100644 lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_event.dart delete mode 100644 lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_state.dart delete mode 100644 lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart delete mode 100644 lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_event.dart delete mode 100644 lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_state.dart delete mode 100644 lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart delete mode 100644 lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_event.dart delete mode 100644 lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_state.dart delete mode 100644 lib/application/plus_button_settings/plus_button_settings_bloc.dart delete mode 100644 lib/application/plus_button_settings/plus_button_settings_event.dart delete mode 100644 lib/application/plus_button_settings/plus_button_settings_state.dart delete mode 100644 lib/application/software_info/software_info_bloc.dart delete mode 100644 lib/application/software_info/software_info_event.dart delete mode 100644 lib/application/software_info/software_info_state.dart delete mode 100644 lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart delete mode 100644 lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_event.dart delete mode 100644 lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_state.dart delete mode 100644 lib/application/vendors/vendors_bloc.dart delete mode 100644 lib/application/vendors/vendors_event.dart delete mode 100644 lib/application/vendors/vendors_state.dart delete mode 100644 lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart delete mode 100644 lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_event.dart delete mode 100644 lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_state.dart delete mode 100644 lib/domain/hub/hub_entity.dart delete mode 100644 lib/domain/hub/hub_errors.dart delete mode 100644 lib/domain/hub/hub_failures.dart delete mode 100644 lib/domain/hub/hub_validators.dart delete mode 100644 lib/domain/hub/hub_value_objects.dart delete mode 100644 lib/infrastructure/hub_client/hub_client.dart delete mode 100644 lib/infrastructure/hub_client/hub_client_demo.dart delete mode 100644 lib/infrastructure/hub_client/hub_dtos.dart delete mode 100644 lib/infrastructure/vendors/vendor_helper.dart delete mode 100644 lib/infrastructure/vendors/vendors_repository.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart delete mode 100644 lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart delete mode 100644 lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart delete mode 100644 lib/presentation/pages/sign_in_page/sign_in_page.dart delete mode 100644 lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart delete mode 100644 lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart delete mode 100644 lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart delete mode 100644 lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart delete mode 100644 lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart delete mode 100644 lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart diff --git a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart b/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart index ab90073e3..59fc4ff97 100644 --- a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart +++ b/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -16,15 +16,13 @@ part 'boilers_actor_state.dart'; @injectable class BoilersActorBloc extends Bloc { - BoilersActorBloc() - : super(const BoilersActorState.initial()) { + BoilersActorBloc() : super(const BoilersActorState.initial()) { on(_deleted); on(_initialized); on(_turnOnAllBoilers); on(_turnOffAllBoilers); } - Future _deleted( Deleted event, Emitter emit, @@ -44,7 +42,8 @@ class BoilersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOnDevices(devicesId: event.boilersIdToTurnUp); + IDeviceRepository.instance + .turnOnDevices(devicesId: event.boilersIdToTurnUp); } Future _turnOffAllBoilers( @@ -56,6 +55,7 @@ class BoilersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOffDevices(devicesId: event.boilersIdToTurnOff); + IDeviceRepository.instance + .turnOffDevices(devicesId: event.boilersIdToTurnOff); } } diff --git a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart index ccf3e7f59..9a7dabe28 100644 --- a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart +++ b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart @@ -22,6 +22,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; import 'package:kt_dart/kt.dart'; import 'package:wifi_iot/wifi_iot.dart'; +import 'package:wifi_scan/wifi_scan.dart'; part 'configure_new_cbj_comp_bloc.freezed.dart'; part 'configure_new_cbj_comp_event.dart'; @@ -223,12 +224,13 @@ class ConfigureNewCbjCompBloc CheckConnectedToWiFiNetwork event, Emitter emit, ) async { - // TODO: Not suer if it will open the WiFi when hotspot is open, delete if not - - await WiFiForIoTPlugin.loadWifiList(); - // TODO: The above line is deprecated, not sure what is the corresponding - // TODO: function in the new package that got transferred to - // await WiFiScan.instance + if ((await WiFiScan.instance.canStartScan()) == CanStartScan.yes) { + await WiFiScan.instance.startScan(); + if ((await WiFiScan.instance.canGetScannedResults()) == + CanGetScannedResults.yes) { + await WiFiScan.instance.getScannedResults(); + } + } bool isConnectedToWifi = false; logger.i('Waiting_for_user_to_get_connected_to_WiFi'.tr()); @@ -236,8 +238,6 @@ class ConfigureNewCbjCompBloc while (true) { isConnectedToWifi = await WiFiForIoTPlugin.isConnected(); if (isConnectedToWifi) { - // TODO: Check if connected to the same WiFI that user set up in the - // first screen, if not show the user massage about it break; } await Future.delayed(const Duration(seconds: 10)); diff --git a/lib/application/devices/device_actor/device_actor_bloc.dart b/lib/application/devices/device_actor/device_actor_bloc.dart index 61c90a55f..53f38724d 100644 --- a/lib/application/devices/device_actor/device_actor_bloc.dart +++ b/lib/application/devices/device_actor/device_actor_bloc.dart @@ -1,9 +1,8 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -13,13 +12,11 @@ part 'device_actor_state.dart'; @injectable class DeviceActorBloc extends Bloc { - DeviceActorBloc() - : super(const DeviceActorState.initial()) { + DeviceActorBloc() : super(const DeviceActorState.initial()) { on(_deleted); on(_initialized); } - Future _deleted( Deleted event, Emitter emit, diff --git a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart b/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart deleted file mode 100644 index b62b0b2c6..000000000 --- a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/esphome_login/generic_esphome_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/esphome_login/generic_esphome_login_value_objects.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'esphome_sign_in_form_bloc.freezed.dart'; -part 'esphome_sign_in_form_event.dart'; -part 'esphome_sign_in_form_state.dart'; - -@injectable -class EspHomeSignInFormBloc - extends Bloc { - EspHomeSignInFormBloc(this._vendorRepository) - : super(EspHomeSignInFormState.initial()) { - on(_apiKeyChanged); - on(_signInWithApiKey); - } - - final IVendorsRepository _vendorRepository; - - // - // @override - // SignInFormState get initialStat`e => SignInFormState.initial(); - - Future _apiKeyChanged( - ApiKeyChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - espHomeDevicePassword: - GenericEspHomeDeviceLoginApiPass(event.apiKeyStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _signInWithApiKey( - SignInWithEspHomeApiKey event, - Emitter emit, - ) async { - final GenericEspHomeLoginDE genericEspHomeDE = GenericEspHomeLoginDE( - senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), - espHomeDevicePass: GenericEspHomeDeviceLoginApiPass( - state.espHomeDevicePassword.getOrCrash(), - ), - ); - _vendorRepository.loginWithEspHome(genericEspHomeDE); - // emit(* _performActionOnAuthFacadeWithEmailAndPassword( - // _authFacade.registerWithEmailAndPassword, - } -} diff --git a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_event.dart b/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_event.dart deleted file mode 100644 index 88a6cc8de..000000000 --- a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'esphome_sign_in_form_bloc.dart'; - -@freezed -class EspHomeSignInFormEvent with _$EspHomeSignInFormEvent { - const factory EspHomeSignInFormEvent.apiKeyChanged(String apiKeyStr) = - ApiKeyChanged; - - const factory EspHomeSignInFormEvent.signInWithEspHomeApiKey() = - SignInWithEspHomeApiKey; -} diff --git a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_state.dart b/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_state.dart deleted file mode 100644 index 0b66ba623..000000000 --- a/lib/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'esphome_sign_in_form_bloc.dart'; - -@freezed -class EspHomeSignInFormState with _$EspHomeSignInFormState { - const factory EspHomeSignInFormState({ - required GenericEspHomeDeviceLoginApiPass espHomeDevicePassword, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _EspHomeSignInFormState; - - factory EspHomeSignInFormState.initial() => EspHomeSignInFormState( - espHomeDevicePassword: GenericEspHomeDeviceLoginApiPass(''), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart b/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart deleted file mode 100644 index 669954f9f..000000000 --- a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/ewelink_login/generic_ewelink_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/ewelink_login/generic_ewelink_login_value_objects.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'ewelink_sign_in_form_bloc.freezed.dart'; -part 'ewelink_sign_in_form_event.dart'; -part 'ewelink_sign_in_form_state.dart'; - -@injectable -class EwelinkSignInFormBloc - extends Bloc { - EwelinkSignInFormBloc(this._vendorRepository) - : super(EwelinkSignInFormState.initial()) { - on(_ewelinkAccountEmailChange); - on(_ewelinkAccountPassChange); - on(_signInWithEwelink); - } - - final IVendorsRepository _vendorRepository; - - // - // @override - // SignInFormState get initialStat`e => SignInFormState.initial(); - - Future _ewelinkAccountEmailChange( - EwelinkAccountEmailChange event, - Emitter emit, - ) async { - emit( - state.copyWith( - ewelinkAccountEmail: GenericEwelinkAccountEmail(event.email), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _ewelinkAccountPassChange( - EwelinkAccountPassChange event, - Emitter emit, - ) async { - emit( - state.copyWith( - ewelinkAccountPass: GenericEwelinkAccountPass(event.pass), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _signInWithEwelink( - SignInWithEwelink event, - Emitter emit, - ) async { - final GenericEwelinkLoginDE genericEwelinkDE = GenericEwelinkLoginDE( - senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), - ewelinkAccountEmail: - GenericEwelinkAccountEmail(state.ewelinkAccountEmail.getOrCrash()), - ewelinkAccountPass: - GenericEwelinkAccountPass(state.ewelinkAccountPass.getOrCrash()), - ); - _vendorRepository.loginWithEwelink(genericEwelinkDE); - // emit(* _performActionOnAuthFacadeWithEmailAndPassword( - // _authFacade.registerWithEmailAndPassword, - } -} diff --git a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_event.dart b/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_event.dart deleted file mode 100644 index 8f059088c..000000000 --- a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_event.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'ewelink_sign_in_form_bloc.dart'; - -@freezed -class EwelinkSignInFormEvent with _$EwelinkSignInFormEvent { - const factory EwelinkSignInFormEvent.ewelinkAccountEmailChange( - String email, - ) = EwelinkAccountEmailChange; - - const factory EwelinkSignInFormEvent.ewelinkAccountPassChange(String pass) = - EwelinkAccountPassChange; - - const factory EwelinkSignInFormEvent.signInWithEwelink() = SignInWithEwelink; -} diff --git a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_state.dart b/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_state.dart deleted file mode 100644 index 85c7b8554..000000000 --- a/lib/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_state.dart +++ /dev/null @@ -1,20 +0,0 @@ -part of 'ewelink_sign_in_form_bloc.dart'; - -@freezed -class EwelinkSignInFormState with _$EwelinkSignInFormState { - const factory EwelinkSignInFormState({ - required GenericEwelinkAccountEmail ewelinkAccountEmail, - required GenericEwelinkAccountPass ewelinkAccountPass, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _EwelinkSignInFormState; - - factory EwelinkSignInFormState.initial() => EwelinkSignInFormState( - ewelinkAccountEmail: GenericEwelinkAccountEmail(''), - ewelinkAccountPass: GenericEwelinkAccountPass(''), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart b/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart deleted file mode 100644 index 095c8b9cd..000000000 --- a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/lifx_login/generic_lifx_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/lifx_login/generic_lifx_login_value_objects.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'lifx_sign_in_form_bloc.freezed.dart'; -part 'lifx_sign_in_form_event.dart'; -part 'lifx_sign_in_form_state.dart'; - -@injectable -class LifxSignInFormBloc - extends Bloc { - LifxSignInFormBloc(this._vendorRepository) - : super(LifxSignInFormState.initial()) { - on(_apiKeyChanged); - on(_signInWithApiKey); - } - - final IVendorsRepository _vendorRepository; - - // - // @override - // SignInFormState get initialStat`e => SignInFormState.initial(); - - Future _apiKeyChanged( - ApiKeyChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - lifxApiKey: GenericLifxLoginApiKey(event.apiKeyStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _signInWithApiKey( - SignInWithLifxApiKey event, - Emitter emit, - ) async { - final GenericLifxLoginDE genericLifxDE = GenericLifxLoginDE( - senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), - lifxApiKey: GenericLifxLoginApiKey(state.lifxApiKey.getOrCrash()), - ); - _vendorRepository.loginWithLifx(genericLifxDE); - // emit(* _performActionOnAuthFacadeWithEmailAndPassword( - // _authFacade.registerWithEmailAndPassword, - } -} diff --git a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_event.dart b/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_event.dart deleted file mode 100644 index e590ad84e..000000000 --- a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'lifx_sign_in_form_bloc.dart'; - -@freezed -class LifxSignInFormEvent with _$LifxSignInFormEvent { - const factory LifxSignInFormEvent.apiKeyChanged(String apiKeyStr) = - ApiKeyChanged; - - const factory LifxSignInFormEvent.signInWithLifxApiKey() = - SignInWithLifxApiKey; -} diff --git a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_state.dart b/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_state.dart deleted file mode 100644 index db9fc9b48..000000000 --- a/lib/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'lifx_sign_in_form_bloc.dart'; - -@freezed -class LifxSignInFormState with _$LifxSignInFormState { - const factory LifxSignInFormState({ - required GenericLifxLoginApiKey lifxApiKey, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _LifxSignInFormState; - - factory LifxSignInFormState.initial() => LifxSignInFormState( - lifxApiKey: GenericLifxLoginApiKey(''), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/light_toggle/light_toggle_bloc.dart b/lib/application/light_toggle/light_toggle_bloc.dart index dbd2195c1..59ab61aea 100644 --- a/lib/application/light_toggle/light_toggle_bloc.dart +++ b/lib/application/light_toggle/light_toggle_bloc.dart @@ -3,9 +3,7 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -56,14 +54,12 @@ class LightToggleBloc extends Bloc { ChangeState event, Emitter emit, ) async { - Either actionResult; - if (event.changeToState) { - actionResult = await IDeviceRepository.instance.turnOnDevices( + await IDeviceRepository.instance.turnOnDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } else { - actionResult = await IDeviceRepository.instance.turnOffDevices( + await IDeviceRepository.instance.turnOffDevices( devicesId: [event.deviceEntity.uniqueId.getOrCrash()], ); } diff --git a/lib/application/lights/lights_actor/lights_actor_bloc.dart b/lib/application/lights/lights_actor/lights_actor_bloc.dart index 000c7110e..305cd771d 100644 --- a/lib/application/lights/lights_actor/lights_actor_bloc.dart +++ b/lib/application/lights/lights_actor/lights_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -15,15 +15,13 @@ part 'lights_actor_state.dart'; @injectable class LightsActorBloc extends Bloc { - LightsActorBloc() - : super(const LightsActorState.initial()) { + LightsActorBloc() : super(const LightsActorState.initial()) { on(_initialized); on(_deleted); on(_turnOffAllLights); on(_turnOnAllLights); } - Future _initialized( Initialized event, Emitter emit, @@ -43,7 +41,8 @@ class LightsActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOffDevices(devicesId: event.lightsIdToTurnOff); + IDeviceRepository.instance + .turnOffDevices(devicesId: event.lightsIdToTurnOff); } Future _turnOnAllLights( diff --git a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart b/lib/application/lights/lights_watcher/lights_watcher_bloc.dart index 522e7111f..683bccbd9 100644 --- a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart +++ b/lib/application/lights/lights_watcher/lights_watcher_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -15,8 +15,7 @@ part 'lights_watcher_state.dart'; @injectable class LightsWatcherBloc extends Bloc { - LightsWatcherBloc() - : super(LightsWatcherState.initial()) { + LightsWatcherBloc() : super(LightsWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } diff --git a/lib/application/more_connections_options/more_connections_options_bloc.dart b/lib/application/more_connections_options/more_connections_options_bloc.dart index 2142cf63a..ee8a41ed6 100644 --- a/lib/application/more_connections_options/more_connections_options_bloc.dart +++ b/lib/application/more_connections_options/more_connections_options_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:auto_route/auto_route.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart'; diff --git a/lib/application/plus_button_settings/plus_button_settings_bloc.dart b/lib/application/plus_button_settings/plus_button_settings_bloc.dart deleted file mode 100644 index da766e996..000000000 --- a/lib/application/plus_button_settings/plus_button_settings_bloc.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'plus_button_settings_bloc.freezed.dart'; -part 'plus_button_settings_event.dart'; -part 'plus_button_settings_state.dart'; - -@injectable -class PlusButtonSettingsBloc - extends Bloc { - PlusButtonSettingsBloc() : super(PlusButtonSettingsState.initial()) { - on(_initialized); - - on(_logout); - } - - late BuildContext context; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - context = event.context; - } - - Future _logout( - Logout event, - Emitter emit, - ) async { - emit(PlusButtonSettingsState.loadInProgress()); - await IHubConnectionRepository.instance.closeConnection(); - - context.router.replace(const ConnectToHubRoute()); - } -} diff --git a/lib/application/plus_button_settings/plus_button_settings_event.dart b/lib/application/plus_button_settings/plus_button_settings_event.dart deleted file mode 100644 index c3ce55c1e..000000000 --- a/lib/application/plus_button_settings/plus_button_settings_event.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of 'plus_button_settings_bloc.dart'; - -@freezed -class PlusButtonSettingsEvent with _$PlusButtonSettingsEvent { - const factory PlusButtonSettingsEvent.initialized(BuildContext context) = - Initialized; - - const factory PlusButtonSettingsEvent.logout() = Logout; -} diff --git a/lib/application/plus_button_settings/plus_button_settings_state.dart b/lib/application/plus_button_settings/plus_button_settings_state.dart deleted file mode 100644 index ff7468406..000000000 --- a/lib/application/plus_button_settings/plus_button_settings_state.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'plus_button_settings_bloc.dart'; - -@freezed -class PlusButtonSettingsState with _$PlusButtonSettingsState { - factory PlusButtonSettingsState.initial() = Initial; - - factory PlusButtonSettingsState.loadInProgress() = LoadInProgress; - - factory PlusButtonSettingsState.loadSuccess() = LoadSuccess; - - factory PlusButtonSettingsState.loadFailure() = LoadFailure; -} diff --git a/lib/application/printers/printers_actor/printers_actor_bloc.dart b/lib/application/printers/printers_actor/printers_actor_bloc.dart index 520304396..23e962d0f 100644 --- a/lib/application/printers/printers_actor/printers_actor_bloc.dart +++ b/lib/application/printers/printers_actor/printers_actor_bloc.dart @@ -6,7 +6,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cybear_jinni/utils.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -18,8 +17,7 @@ part 'printers_actor_state.dart'; @injectable class PrintersActorBloc extends Bloc { - PrintersActorBloc() - : super(const PrintersActorState.initial()) { + PrintersActorBloc() : super(const PrintersActorState.initial()) { on(_initialized); on(_deleted); on(_turnOffAllPrinters); @@ -28,7 +26,6 @@ class PrintersActorBloc extends Bloc { on(_shutdownAllPrinters); } - Future _initialized( Initialized event, Emitter emit, @@ -48,7 +45,7 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOffDevices( + IDeviceRepository.instance.turnOffDevices( devicesId: event.printersIdToTurnOff, ); } @@ -62,7 +59,8 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOnDevices(devicesId: event.printersIdToTurnOn); + IDeviceRepository.instance + .turnOnDevices(devicesId: event.printersIdToTurnOn); } Future _openPrintersWebPage( @@ -75,19 +73,10 @@ class PrintersActorBloc extends Bloc { ).show(event.context); final String printerIp = event.printer.deviceLastKnownIp.getOrCrash(); - if (printerIp != null) { - launchUrl( - Uri.parse('http://$printerIp'), - mode: LaunchMode.externalApplication, - ); - } else { - logger.e('Printer does not have lastKnownIp'); - - FlushbarHelper.createLoading( - message: 'Printer last ip does not exist', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - } + launchUrl( + Uri.parse('http://$printerIp'), + mode: LaunchMode.externalApplication, + ); } Future _shutdownAllPrinters( @@ -99,6 +88,6 @@ class PrintersActorBloc extends Bloc { linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.shutdownDevices(devicesId: event.printersId); + IDeviceRepository.instance.shutdownDevices(devicesId: event.printersId); } } diff --git a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart b/lib/application/printers/printers_watcher/printers_watcher_bloc.dart index d51daef37..512595fcc 100644 --- a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart +++ b/lib/application/printers/printers_watcher/printers_watcher_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,8 +16,7 @@ part 'printers_watcher_state.dart'; @injectable class PrintersWatcherBloc extends Bloc { - PrintersWatcherBloc() - : super(PrintersWatcherState.initial()) { + PrintersWatcherBloc() : super(PrintersWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } @@ -31,9 +30,11 @@ class PrintersWatcherBloc ) async { emit(const PrintersWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchPrinters().listen( - (eventWatch) => add(PrintersWatcherEvent.devicesReceived(eventWatch)), - ); + _deviceStreamSubscription = + IDeviceRepository.instance.watchPrinters().listen( + (eventWatch) => + add(PrintersWatcherEvent.devicesReceived(eventWatch)), + ); } Future _devicesReceived( diff --git a/lib/application/remote_pipes/remote_pipes_bloc.dart b/lib/application/remote_pipes/remote_pipes_bloc.dart index 53876dcf1..eb81755aa 100644 --- a/lib/application/remote_pipes/remote_pipes_bloc.dart +++ b/lib/application/remote_pipes/remote_pipes_bloc.dart @@ -58,8 +58,8 @@ class RemotePipesBloc extends Bloc { ), ); - final remotePipesSetDomainResponse = await IRemotePipesRepository.instance - .setRemotePipesDomainName(remotePipesEntity); Navigator.pop(event.context); + await IRemotePipesRepository.instance + .setRemotePipesDomainName(remotePipesEntity); } } diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart index e5d7affa7..5716a12b1 100644 --- a/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart +++ b/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart @@ -25,5 +25,6 @@ class SecurityCamerasActorEvent with _$SecurityCamerasActorEvent { ) = ShutdownAllSecurityCameras; const factory SecurityCamerasActorEvent.deleted( - GenericSwitchDE deviceEntity) = Deleted; + GenericSwitchDE deviceEntity, + ) = Deleted; } diff --git a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart index 0d5879c58..50847a797 100644 --- a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart +++ b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,8 +16,7 @@ part 'smart_computers_actor_state.dart'; @injectable class SmartComputersActorBloc extends Bloc { - SmartComputersActorBloc() - : super(const SmartComputersActorState.initial()) { + SmartComputersActorBloc() : super(const SmartComputersActorState.initial()) { on(_initialized); on(_deleted); on(_turnOffAllSmartComputers); @@ -45,7 +44,7 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOffDevices( + IDeviceRepository.instance.turnOffDevices( devicesId: event.smartComputersIdToTurnOff, ); } @@ -59,7 +58,8 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOnDevices(devicesId: event.smartComputersIdToTurnOn); + IDeviceRepository.instance + .turnOnDevices(devicesId: event.smartComputersIdToTurnOn); } Future _suspendAllSmartComputers( @@ -71,7 +71,8 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.suspendDevices(devicesId: event.smartComputersId); + IDeviceRepository.instance + .suspendDevices(devicesId: event.smartComputersId); } Future _shutdownAllSmartComputers( @@ -83,6 +84,7 @@ class SmartComputersActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.shutdownDevices(devicesId: event.smartComputersId); + IDeviceRepository.instance + .shutdownDevices(devicesId: event.smartComputersId); } } diff --git a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart index 4d445d23c..14774d861 100644 --- a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart +++ b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,8 +16,7 @@ part 'smart_computer_watcher_state.dart'; @injectable class SmartComputersWatcherBloc extends Bloc { - SmartComputersWatcherBloc() - : super(SmartComputersWatcherState.initial()) { + SmartComputersWatcherBloc() : super(SmartComputersWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } @@ -31,10 +30,11 @@ class SmartComputersWatcherBloc ) async { emit(const SmartComputersWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchSmartComputers().listen( - (eventWatch) => - add(SmartComputersWatcherEvent.devicesReceived(eventWatch)), - ); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSmartComputers().listen( + (eventWatch) => + add(SmartComputersWatcherEvent.devicesReceived(eventWatch)), + ); } Future _devicesReceived( diff --git a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart b/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart index 805ab59e7..3b58193e6 100644 --- a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart +++ b/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/widgets.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -16,14 +16,12 @@ part 'smart_plug_toggle_state.dart'; @injectable class SmartPlugToggleBloc extends Bloc { - SmartPlugToggleBloc() - : super(SmartPlugToggleState.initial()) { + SmartPlugToggleBloc() : super(SmartPlugToggleState.initial()) { on(_create); on(_changeAction); on(_changeColor); } - int sendNewColorEachMiliseconds = 200; Timer? timeFromLastColorChange; HSVColor? lastColoredPicked; @@ -32,7 +30,7 @@ class SmartPlugToggleBloc CreateDevice event, Emitter emit, ) async { - final actionResult = await IDeviceRepository.instance.create(event.deviceEntity); + await IDeviceRepository.instance.create(event.deviceEntity); } Future _changeAction( diff --git a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart index 179862530..2c2438011 100644 --- a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart +++ b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart @@ -2,9 +2,9 @@ import 'dart:async'; import 'package:another_flushbar/flushbar_helper.dart'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,15 +16,13 @@ part 'smart_plugs_actor_state.dart'; @injectable class SmartPlugsActorBloc extends Bloc { - SmartPlugsActorBloc() - : super(const SmartPlugsActorState.initial()) { + SmartPlugsActorBloc() : super(const SmartPlugsActorState.initial()) { on(_initialized); on(_deleted); on(_turnOffAllSmartPlugs); on(_turnOnAllSmartPlugs); } - Future _initialized( Initialized event, Emitter emit, @@ -44,7 +42,8 @@ class SmartPlugsActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOffDevices(devicesId: event.smartPlugsIdToTurnOff); + IDeviceRepository.instance + .turnOffDevices(devicesId: event.smartPlugsIdToTurnOff); } Future _turnOnAllSmartPlugs( @@ -56,6 +55,7 @@ class SmartPlugsActorBloc linearProgressIndicator: const LinearProgressIndicator(), ).show(event.context); - IDeviceRepository.instance.turnOnDevices(devicesId: event.smartPlugsIdToTurnOn); + IDeviceRepository.instance + .turnOnDevices(devicesId: event.smartPlugsIdToTurnOn); } } diff --git a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart index 3ffe207bd..5fa0b219e 100644 --- a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart +++ b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,8 +16,7 @@ part 'smart_plugs_watcher_state.dart'; @injectable class SmartPlugsWatcherBloc extends Bloc { - SmartPlugsWatcherBloc() - : super(SmartPlugsWatcherState.initial()) { + SmartPlugsWatcherBloc() : super(SmartPlugsWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } @@ -31,10 +30,11 @@ class SmartPlugsWatcherBloc ) async { emit(const SmartPlugsWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchSmartPlugs().listen( - (eventWatch) => - add(SmartPlugsWatcherEvent.devicesReceived(eventWatch)), - ); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSmartPlugs().listen( + (eventWatch) => + add(SmartPlugsWatcherEvent.devicesReceived(eventWatch)), + ); } Future _devicesReceived( diff --git a/lib/application/software_info/software_info_bloc.dart b/lib/application/software_info/software_info_bloc.dart deleted file mode 100644 index 0547e1f8a..000000000 --- a/lib/application/software_info/software_info_bloc.dart +++ /dev/null @@ -1,74 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/software_info/i_software_info_repository.dart'; -import 'package:cybear_jinni/domain/software_info/software_info_entity.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'software_info_bloc.freezed.dart'; -part 'software_info_event.dart'; -part 'software_info_state.dart'; - -@injectable -class SoftwareInfoBloc extends Bloc { - SoftwareInfoBloc() : super(SoftwareInfoState.initial()) { - on(_initialized); - on(_getSoftwareInfo); - } - - Map softwaresInfo = {}; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - SoftwareInfoEntity? appInfoEntity; - (await ISoftwareInfoRepository.instance.getAppSoftwareInfo()).fold( - (l) => l, - (r) { - appInfoEntity = r; - }, - ); - - if (appInfoEntity != null) { - softwaresInfo.addEntries([MapEntry('App Server', appInfoEntity!)]); - emit(SoftwareInfoState.gotSoftwareInfoEntities(softwaresInfo)); - } - - SoftwareInfoEntity? hubInfoEntity; - (await ISoftwareInfoRepository.instance.getHubSoftwareInfo()).fold( - (l) => l, - (r) { - hubInfoEntity = r; - }, - ); - - if (hubInfoEntity != null) { - softwaresInfo.addEntries([MapEntry('Hub Server', hubInfoEntity!)]); - emit(SoftwareInfoState.initial()); - emit(SoftwareInfoState.gotSoftwareInfoEntities(softwaresInfo)); - } - - SoftwareInfoEntity? securityBearInfoEntity; - (await ISoftwareInfoRepository.instance.getSecurityBearSoftwareInfo()).fold( - (l) => l, - (r) { - securityBearInfoEntity = r; - }, - ); - - if (securityBearInfoEntity != null) { - softwaresInfo.addEntries([ - MapEntry('Security Bear Server', securityBearInfoEntity!), - ]); - emit(SoftwareInfoState.initial()); - emit(SoftwareInfoState.gotSoftwareInfoEntities(softwaresInfo)); - } - } - - Future _getSoftwareInfo( - GetSoftwareInfo event, - Emitter emit, - ) async {} -} diff --git a/lib/application/software_info/software_info_event.dart b/lib/application/software_info/software_info_event.dart deleted file mode 100644 index be1fa1b26..000000000 --- a/lib/application/software_info/software_info_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'software_info_bloc.dart'; - -@freezed -class SoftwareInfoEvent with _$SoftwareInfoEvent { - const factory SoftwareInfoEvent.initialized() = Initialized; - - const factory SoftwareInfoEvent.getSoftwareInfo() = GetSoftwareInfo; -} diff --git a/lib/application/software_info/software_info_state.dart b/lib/application/software_info/software_info_state.dart deleted file mode 100644 index 6557ce7c2..000000000 --- a/lib/application/software_info/software_info_state.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'software_info_bloc.dart'; - -@freezed -class SoftwareInfoState with _$SoftwareInfoState { - factory SoftwareInfoState.initial() = Initial; - - factory SoftwareInfoState.gotSoftwareInfoEntities( - Map softwareInfoEntities, - ) = GotSoftwareInfoEntities; -} diff --git a/lib/application/switch_toggle/switch_toggle_bloc.dart b/lib/application/switch_toggle/switch_toggle_bloc.dart index a79a993ce..68b884ab2 100644 --- a/lib/application/switch_toggle/switch_toggle_bloc.dart +++ b/lib/application/switch_toggle/switch_toggle_bloc.dart @@ -29,8 +29,7 @@ class SwitchToggleBloc extends Bloc { CreateDevice event, Emitter emit, ) async { - final actionResult = - await IDeviceRepository.instance.create(event.deviceEntity); + await IDeviceRepository.instance.create(event.deviceEntity); } Future _changeAction( diff --git a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart b/lib/application/switches/switches_watcher/switches_watcher_bloc.dart index 95fd3fcc3..da6299eae 100644 --- a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart +++ b/lib/application/switches/switches_watcher/switches_watcher_bloc.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:dartz/dartz.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:injectable/injectable.dart'; @@ -16,8 +16,7 @@ part 'switches_watcher_state.dart'; @injectable class SwitchesWatcherBloc extends Bloc { - SwitchesWatcherBloc() - : super(SwitchesWatcherState.initial()) { + SwitchesWatcherBloc() : super(SwitchesWatcherState.initial()) { on(_watchAllStarted); on(_devicesReceived); } @@ -31,9 +30,11 @@ class SwitchesWatcherBloc ) async { emit(const SwitchesWatcherState.loadInProgress()); await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchSwitches().listen( - (eventWatch) => add(SwitchesWatcherEvent.devicesReceived(eventWatch)), - ); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSwitches().listen( + (eventWatch) => + add(SwitchesWatcherEvent.devicesReceived(eventWatch)), + ); } Future _devicesReceived( diff --git a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart b/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart deleted file mode 100644 index c545a4adf..000000000 --- a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart +++ /dev/null @@ -1,144 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; -import 'package:cbj_integrations_controller/domain/vendors/tuya_login/generic_tuya_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/tuya_login/generic_tuya_login_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/utils.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'tuya_sign_in_form_bloc.freezed.dart'; -part 'tuya_sign_in_form_event.dart'; -part 'tuya_sign_in_form_state.dart'; - -@injectable -class TuyaSignInFormBloc - extends Bloc { - TuyaSignInFormBloc(this._vendorRepository) - : super(TuyaSignInFormState.initial()) { - on(_signIn); - on(_vendorChanged); - on(_userNameChanged); - on(_userPasswordChanged); - on(_countryCodeChanged); - on(_bizTypeChanged); - on(_regionChanged); - } - - final IVendorsRepository _vendorRepository; - - // - // @override - // SignInFormState get initialStat`e => SignInFormState.initial(); - - Future _signIn( - SignInWithTuyaApiKey event, - Emitter emit, - ) async { - if (state.tuyaVendor.getOrCrash() == - VendorsAndServices.vendorsAndServicesNotSupported.name) { - logger.e("Tuya vendor type didn't got updated, this should not happen"); - return; - } - final GenericTuyaLoginDE genericTuyaDE = GenericTuyaLoginDE( - senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), - loginVendor: CoreLoginVendor( - state.tuyaVendor.getOrCrash(), - ), - tuyaUserName: GenericTuyaLoginUserName( - state.tuyaUserName.getOrCrash(), - ), - tuyaUserPassword: GenericTuyaLoginUserPassword( - state.tuyaUserPassword.getOrCrash(), - ), - tuyaCountryCode: GenericTuyaLoginCountryCode( - state.tuyaCountryCode.getOrCrash(), - ), - tuyaBizType: GenericTuyaLoginBizType( - state.tuyaBizType.getOrCrash(), - ), - tuyaRegion: GenericTuyaLoginRegion( - state.tuyaLoginRegion.getOrCrash(), - ), - ); - - _vendorRepository.loginWithTuya(genericTuyaDE); - } - - Future _vendorChanged( - VendorChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaVendor: CoreLoginVendor(event.loginVendor), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _userNameChanged( - UserNameChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaUserName: GenericTuyaLoginUserName(event.userNameStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _userPasswordChanged( - UserPasswordChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaUserPassword: GenericTuyaLoginUserPassword(event.userPasswordStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _countryCodeChanged( - CountryCodeChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaCountryCode: GenericTuyaLoginCountryCode(event.countryCodeStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _bizTypeChanged( - BizTypeChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaBizType: GenericTuyaLoginBizType(event.bizTypeStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _regionChanged( - RegionChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - tuyaLoginRegion: GenericTuyaLoginRegion(event.regionStr), - authFailureOrSuccessOption: none(), - ), - ); - } -} diff --git a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_event.dart b/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_event.dart deleted file mode 100644 index 1ab8c17a0..000000000 --- a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_event.dart +++ /dev/null @@ -1,26 +0,0 @@ -part of 'tuya_sign_in_form_bloc.dart'; - -@freezed -class TuyaSignInFormEvent with _$TuyaSignInFormEvent { - const factory TuyaSignInFormEvent.vendorChanged(String loginVendor) = - VendorChanged; - - const factory TuyaSignInFormEvent.userNameChanged(String userNameStr) = - UserNameChanged; - - const factory TuyaSignInFormEvent.userPasswordChanged( - String userPasswordStr, - ) = UserPasswordChanged; - - const factory TuyaSignInFormEvent.countryCodeChanged(String countryCodeStr) = - CountryCodeChanged; - - const factory TuyaSignInFormEvent.bizTypeChanged(String bizTypeStr) = - BizTypeChanged; - - const factory TuyaSignInFormEvent.regionChanged(String? regionStr) = - RegionChanged; - - const factory TuyaSignInFormEvent.signInWithTuyaApiKey() = - SignInWithTuyaApiKey; -} diff --git a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_state.dart b/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_state.dart deleted file mode 100644 index ddc28fa6f..000000000 --- a/lib/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_state.dart +++ /dev/null @@ -1,30 +0,0 @@ -part of 'tuya_sign_in_form_bloc.dart'; - -@freezed -class TuyaSignInFormState with _$TuyaSignInFormState { - const factory TuyaSignInFormState({ - required CoreLoginVendor tuyaVendor, - required GenericTuyaLoginUserName tuyaUserName, - required GenericTuyaLoginUserPassword tuyaUserPassword, - required GenericTuyaLoginCountryCode tuyaCountryCode, - required GenericTuyaLoginBizType tuyaBizType, - required GenericTuyaLoginRegion tuyaLoginRegion, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _TuyaSignInFormState; - - factory TuyaSignInFormState.initial() => TuyaSignInFormState( - tuyaVendor: CoreLoginVendor( - VendorsAndServices.vendorsAndServicesNotSupported.name, - ), - tuyaUserName: GenericTuyaLoginUserName(''), - tuyaUserPassword: GenericTuyaLoginUserPassword(''), - tuyaCountryCode: GenericTuyaLoginCountryCode(''), - tuyaBizType: GenericTuyaLoginBizType('tuya'), - tuyaLoginRegion: GenericTuyaLoginRegion('eu'), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/vendors/vendors_bloc.dart b/lib/application/vendors/vendors_bloc.dart deleted file mode 100644 index 4f31c24fa..000000000 --- a/lib/application/vendors/vendors_bloc.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'vendors_bloc.freezed.dart'; -part 'vendors_event.dart'; -part 'vendors_state.dart'; - -@injectable -class VendorsBloc extends Bloc { - VendorsBloc(this._vendorRepository) : super(VendorsState.initialized()) { - on(_initialized); - } - - final IVendorsRepository _vendorRepository; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - final vendorsList = await _vendorRepository.getVendors(); - emit( - vendorsList.fold( - (f) => const VendorsState.error(), - (vendorsListSuccess) => VendorsState.loaded(vendorsListSuccess), - ), - ); - } -} diff --git a/lib/application/vendors/vendors_event.dart b/lib/application/vendors/vendors_event.dart deleted file mode 100644 index 797da9749..000000000 --- a/lib/application/vendors/vendors_event.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'vendors_bloc.dart'; - -@freezed -class VendorsEvent with _$VendorsEvent { - const factory VendorsEvent.initialized() = Initialized; -} diff --git a/lib/application/vendors/vendors_state.dart b/lib/application/vendors/vendors_state.dart deleted file mode 100644 index 11baa867f..000000000 --- a/lib/application/vendors/vendors_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'vendors_bloc.dart'; - -@freezed -class VendorsState with _$VendorsState { - const factory VendorsState({ - required Option> authFailureOrSuccessOption, - }) = _VendorsEvent; -// }) = _AddServiceState; - - factory VendorsState.initialized() => VendorsState( - authFailureOrSuccessOption: none(), - ); - - const factory VendorsState.loading() = Loading; - - const factory VendorsState.loaded(KtList vendorsList) = Loaded; - - const factory VendorsState.error() = Error; -} diff --git a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart b/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart deleted file mode 100644 index 139ffade9..000000000 --- a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; -import 'package:cbj_integrations_controller/domain/vendors/xiaomi_mi_login/generic_xiaomi_mi_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/xiaomi_mi_login/generic_xiaomi_mi_login_value_objects.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'xiaomi_mi_sign_in_form_bloc.freezed.dart'; -part 'xiaomi_mi_sign_in_form_event.dart'; -part 'xiaomi_mi_sign_in_form_state.dart'; - -@injectable -class XiaomiMiSignInFormBloc - extends Bloc { - XiaomiMiSignInFormBloc(this._vendorRepository) - : super(XiaomiMiSignInFormState.initial()) { - on(_xiaomiMiAccountEmailChange); - on(_xiaomiMiAccountPassChange); - on(_signInWithXiaoMi); - } - - final IVendorsRepository _vendorRepository; - - // - // @override - // SignInFormState get initialStat`e => SignInFormState.initial(); - - Future _xiaomiMiAccountEmailChange( - XiaomiMiAccountEmailChange event, - Emitter emit, - ) async { - emit( - state.copyWith( - xiaomiMiAccountEmail: GenericXiaomiMiAccountEmail(event.email), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _xiaomiMiAccountPassChange( - XiaomiMiAccountPassChange event, - Emitter emit, - ) async { - emit( - state.copyWith( - xiaomiMiAccountPass: GenericXiaomiMiAccountPass(event.pass), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _signInWithXiaoMi( - SignInWithXiaoMi event, - Emitter emit, - ) async { - final GenericXiaomiMiLoginDE genericXiaomiMiDE = GenericXiaomiMiLoginDE( - senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), - xiaomiMiAccountEmail: - GenericXiaomiMiAccountEmail(state.xiaomiMiAccountEmail.getOrCrash()), - xiaomiMiAccountPass: - GenericXiaomiMiAccountPass(state.xiaomiMiAccountPass.getOrCrash()), - ); - _vendorRepository.loginWithXiaomiMi(genericXiaomiMiDE); - // emit(* _performActionOnAuthFacadeWithEmailAndPassword( - // _authFacade.registerWithEmailAndPassword, - } -} diff --git a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_event.dart b/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_event.dart deleted file mode 100644 index 3920747e7..000000000 --- a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_event.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'xiaomi_mi_sign_in_form_bloc.dart'; - -@freezed -class XiaomiMiSignInFormEvent with _$XiaomiMiSignInFormEvent { - const factory XiaomiMiSignInFormEvent.xiaomiMiAccountEmailChange( - String email, - ) = XiaomiMiAccountEmailChange; - - const factory XiaomiMiSignInFormEvent.xiaomiMiAccountPassChange(String pass) = - XiaomiMiAccountPassChange; - - const factory XiaomiMiSignInFormEvent.signInWithXiaoMi() = SignInWithXiaoMi; -} diff --git a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_state.dart b/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_state.dart deleted file mode 100644 index 63923cb09..000000000 --- a/lib/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_state.dart +++ /dev/null @@ -1,20 +0,0 @@ -part of 'xiaomi_mi_sign_in_form_bloc.dart'; - -@freezed -class XiaomiMiSignInFormState with _$XiaomiMiSignInFormState { - const factory XiaomiMiSignInFormState({ - required GenericXiaomiMiAccountEmail xiaomiMiAccountEmail, - required GenericXiaomiMiAccountPass xiaomiMiAccountPass, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _XiaomiMiSignInFormState; - - factory XiaomiMiSignInFormState.initial() => XiaomiMiSignInFormState( - xiaomiMiAccountEmail: GenericXiaomiMiAccountEmail(''), - xiaomiMiAccountPass: GenericXiaomiMiAccountPass(''), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/domain/cbj_comp/cbj_comp_value_objects.dart b/lib/domain/cbj_comp/cbj_comp_value_objects.dart index 93cbc3008..f18ee5530 100644 --- a/lib/domain/cbj_comp/cbj_comp_value_objects.dart +++ b/lib/domain/cbj_comp/cbj_comp_value_objects.dart @@ -1,7 +1,7 @@ +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_errors.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_validators.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart'; import 'package:kt_dart/collection.dart'; diff --git a/lib/domain/hub/hub_entity.dart b/lib/domain/hub/hub_entity.dart deleted file mode 100644 index c4bbdf09f..000000000 --- a/lib/domain/hub/hub_entity.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; -import 'package:cybear_jinni/domain/hub/hub_value_objects.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_dtos.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'hub_entity.freezed.dart'; - -@freezed -abstract class HubEntity implements _$HubEntity { - const factory HubEntity({ - required HubNetworkBssid hubNetworkBssid, - required HubNetworkName networkName, - required HubNetworkIp lastKnownIp, - HubMdnsName? mdnsName, - }) = _HubEntity; - - const HubEntity._(); - - factory HubEntity.empty() => HubEntity( - hubNetworkBssid: HubNetworkBssid(''), - networkName: HubNetworkName(''), - lastKnownIp: HubNetworkIp(''), - ); - - HubDtos toInfrastructure() { - return HubDtos( - hubNetworkBssid: hubNetworkBssid.getOrCrash(), - networkName: networkName.getOrCrash(), - lastKnownIp: lastKnownIp.getOrCrash(), - // serverTimeStamp: FieldValue.serverTimestamp(), - ); - } - - Option> get failureOption { - return lastKnownIp.value.fold((f) => some(f), (_) => none()); - } -} diff --git a/lib/domain/hub/hub_errors.dart b/lib/domain/hub/hub_errors.dart deleted file mode 100644 index 47da86cf1..000000000 --- a/lib/domain/hub/hub_errors.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; - -class HubUnexpectedValueError extends Error { - HubUnexpectedValueError(this.homeUserValueFailure); - - final HubFailures homeUserValueFailure; - - @override - String toString() { - const explanation = - 'Encountered a ValueFailure at an unrecoverable point. Terminating.'; - return Error.safeToString( - '$explanation Failure was: $homeUserValueFailure', - ); - } -} diff --git a/lib/domain/hub/hub_failures.dart b/lib/domain/hub/hub_failures.dart deleted file mode 100644 index bec8b129e..000000000 --- a/lib/domain/hub/hub_failures.dart +++ /dev/null @@ -1,30 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'hub_failures.freezed.dart'; - -@freezed -class HubFailures { - const factory HubFailures.empty({ - required T failedValue, - }) = _Empty; - - const factory HubFailures.unexpected() = _Unexpected; - - const factory HubFailures.validateEmailNotEmpty() = _ValidateEmailNotEmpty; - - const factory HubFailures.insufficientPermission() = _InsufficientPermission; - - const factory HubFailures.wifiIsClosed() = _WifiIsClosed; - - const factory HubFailures.findingHubWhenConnectedToEthernetCableIsNotSupported() = - _FindingHubWhenConnectedToEthernetCableIsNotSupported; - - const factory HubFailures.unableToUpdate() = _UnableToUpdate; - - const factory HubFailures.cantFindHubInNetwork() = _CantFindHubInNetwork; - - const factory HubFailures.hubFoundButNotRunning() = _HubFoundButNotRunning; - - const factory HubFailures.automaticHubSearchNotSupportedOnWeb() = - _AutomaticHubSearchNotSupportedOnWeb; -} diff --git a/lib/domain/hub/hub_validators.dart b/lib/domain/hub/hub_validators.dart deleted file mode 100644 index b5a7e9552..000000000 --- a/lib/domain/hub/hub_validators.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; -import 'package:dartz/dartz.dart'; - -Either, String> validateStringNotEmpty(String input) { - if (input.isNotEmpty) { - return right(input); - } else { - return left( - HubFailures.empty( - failedValue: input, - ), - ); - } -} diff --git a/lib/domain/hub/hub_value_objects.dart b/lib/domain/hub/hub_value_objects.dart deleted file mode 100644 index b33efe2f5..000000000 --- a/lib/domain/hub/hub_value_objects.dart +++ /dev/null @@ -1,89 +0,0 @@ -import 'package:cybear_jinni/domain/hub/hub_errors.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; -import 'package:cybear_jinni/domain/hub/hub_validators.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/foundation.dart'; - -@immutable -abstract class HubValueObjectAbstract { - const HubValueObjectAbstract(); - - Either, T> get value; - - /// Throws [UnexpectedValueError] containing the [HubFailures] - T getOrCrash() { - // id = identity - same as writing (right) => right - return value.fold((f) => throw HubUnexpectedValueError(f), id); - } - - Either, Unit> get failureOrUnit { - return value.fold((l) => left(l), (r) => right(unit)); - } - - bool isValid() => value.isRight(); - - @override - String toString() => 'Value($value)'; - - @override - @nonVirtual - bool operator ==(Object o) { - if (identical(this, o)) return true; - return o is HubValueObjectAbstract && o.value == value; - } - - @override - int get hashCode => value.hashCode; -} - -class HubNetworkIp extends HubValueObjectAbstract { - factory HubNetworkIp(String input) { - return HubNetworkIp._( - validateStringNotEmpty(input), - ); - } - - const HubNetworkIp._(this.value); - - @override - final Either, String> value; -} - -class HubMdnsName extends HubValueObjectAbstract { - factory HubMdnsName(String input) { - return HubMdnsName._( - validateStringNotEmpty(input), - ); - } - - const HubMdnsName._(this.value); - - @override - final Either, String> value; -} - -class HubNetworkBssid extends HubValueObjectAbstract { - factory HubNetworkBssid(String input) { - return HubNetworkBssid._( - validateStringNotEmpty(input), - ); - } - - const HubNetworkBssid._(this.value); - - @override - final Either, String> value; -} - -class HubNetworkName extends HubValueObjectAbstract { - factory HubNetworkName(String input) { - return HubNetworkName._( - validateStringNotEmpty(input), - ); - } - - const HubNetworkName._(this.value); - - @override - final Either, String> value; -} diff --git a/lib/domain/hub/i_hub_connection_repository.dart b/lib/domain/hub/i_hub_connection_repository.dart index c2526e3c3..cfa480419 100644 --- a/lib/domain/hub/i_hub_connection_repository.dart +++ b/lib/domain/hub/i_hub_connection_repository.dart @@ -1,10 +1,10 @@ +import 'package:cbj_integrations_controller/domain/hub/hub_entity.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/domain/hub/hub_entity.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_connection_repository.dart'; import 'package:dartz/dartz.dart'; -abstract interface class IHubConnectionRepository { +abstract class IHubConnectionRepository { static IHubConnectionRepository? _instance; static IHubConnectionRepository get instance { diff --git a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart b/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart index 2a51bd3ab..a4f343350 100644 --- a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart +++ b/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart @@ -4,7 +4,6 @@ import 'package:cybear_jinni/domain/add_user_to_home/i_add_user_to_home_reposito import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; import 'package:cybear_jinni/infrastructure/home_user/home_user_dtos.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -20,11 +19,11 @@ class AddUserToHomeRepository implements IAddUserToHomeRepository { try { // final devicesDoc = await _firestore.currentHomeDocument(); // - final String userId = homeUserEntity.id!.getOrCrash()!; + homeUserEntity.id!.getOrCrash()!; // final String userName = addUserToHomeEntity.name.getOrCrash(); // final String userEmail = addUserToHomeEntity.email.getOrCrash(); - final HomeUserDtos homeUserDtos = HomeUserDtos.fromDomain(homeUserEntity); + HomeUserDtos.fromDomain(homeUserEntity); // await devicesDoc.usersCollecttion.doc(userId).set(homeUserDtos.toJson()); return right(unit); @@ -67,7 +66,7 @@ class AddUserToHomeRepository implements IAddUserToHomeRepository { final Either> userDocOrFailure = await getUserByEmail(homeUserEntity.email!.getOrCrash()!); - final Map userDocument = userDocOrFailure.fold( + userDocOrFailure.fold( (f) => throw AddUserToHomeUnexpectedValueError(f), (r) => r, ); diff --git a/lib/infrastructure/cbj_app_server/cbj_app_server_d.dart b/lib/infrastructure/cbj_app_server/cbj_app_server_d.dart index 847db50f9..2be8a4498 100644 --- a/lib/infrastructure/cbj_app_server/cbj_app_server_d.dart +++ b/lib/infrastructure/cbj_app_server/cbj_app_server_d.dart @@ -47,7 +47,7 @@ class CreateTheCBJAppServer { /// This function will create the server Future createServer(StreamController compInfoStream) async { await server?.shutdown(); - server = Server([CBJAppServerD(compInfoStream)]); + server = Server.create(services: [CBJAppServerD(compInfoStream)]); await server!.serve(port: 30055); logger.i('App server listening on port ${server!.port}...'); } diff --git a/lib/infrastructure/create_home/create_home_repository.dart b/lib/infrastructure/create_home/create_home_repository.dart index fdf79b334..14df9a2ae 100644 --- a/lib/infrastructure/create_home/create_home_repository.dart +++ b/lib/infrastructure/create_home/create_home_repository.dart @@ -19,7 +19,6 @@ import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/domain/user/user_errors.dart'; import 'package:cybear_jinni/domain/user/user_failures.dart'; import 'package:cybear_jinni/infrastructure/create_home/create_home_dtos.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; @@ -136,8 +135,7 @@ class CreateHomeRepository implements ICreateHomeRepository { CreateHomeEntity createHomeEntity, ) async { try { - final CreateHomeDtos deviceHomeUserDtos = - CreateHomeDtos.fromDomain(createHomeEntity); + CreateHomeDtos.fromDomain(createHomeEntity); // await homeDoc.devicesUsersCollecttion // .doc('default') diff --git a/lib/infrastructure/devices/device/device_repository.dart b/lib/infrastructure/devices/device/device_repository.dart index 3e45714fb..a8fa77d5a 100644 --- a/lib/infrastructure/devices/device/device_repository.dart +++ b/lib/infrastructure/devices/device/device_repository.dart @@ -25,17 +25,17 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_value_objects.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_value_objects.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/domain/user/i_user_repository.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_requests_routing.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:device_info_plus/device_info_plus.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter/src/painting/colors.dart'; import 'package:kt_dart/kt.dart'; import 'package:multicast_dns/multicast_dns.dart'; import 'package:network_info_plus/network_info_plus.dart'; @@ -80,7 +80,6 @@ class DeviceRepository implements IDeviceRepository { @override Future initiateHubConnection() async { AppRequestsToHub.listenToApp(); - HubRequestsToApp.listenToApp(); HubRequestRouting.navigateRequest(); } diff --git a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart b/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart index 5af91d637..08db77f67 100644 --- a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart +++ b/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart @@ -8,7 +8,6 @@ import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; import 'package:cybear_jinni/domain/user/i_user_repository.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/domain/user/user_value_objects.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; class HubAuthFacade implements IAuthFacade { @@ -49,7 +48,6 @@ class HubAuthFacade implements IAuthFacade { Password? password, }) async { final emailAddressStr = emailAddress!.getOrCrash(); - final passwordStr = password!.getOrCrash(); try { // final UserCredential userCredential = @@ -88,9 +86,6 @@ class HubAuthFacade implements IAuthFacade { required EmailAddress emailAddress, required Password password, }) async { - final emailAddressStr = emailAddress.getOrCrash(); - final passwordStr = password.getOrCrash(); - try { return right(unit); } catch (e) { diff --git a/lib/infrastructure/hub_client/hub_client.dart b/lib/infrastructure/hub_client/hub_client.dart deleted file mode 100644 index 39811799e..000000000 --- a/lib/infrastructure/hub_client/hub_client.dart +++ /dev/null @@ -1,114 +0,0 @@ -import 'dart:async'; - -import 'package:async/async.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cbj_integrations_controller/utils.dart'; -import 'package:grpc/grpc.dart'; - -class HubClient { - static ClientChannel? channel; - static CbjHubClient? stub; - - /// Creates a stream with the Hub - static Future createStreamWithHub( - String addressToHub, - int hubPort, - ) async { - await channel?.terminate(); - - channel = await _createCbjHubClient(addressToHub, hubPort); - channel!.onConnectionStateChanged.listen((event) { - logger.i('gRPC connection state $event'); - }); - stub = CbjHubClient(channel!); - ResponseStream response; - - try { - response = stub!.clientTransferEntities( - AppRequestsToHub.appRequestsToHubStreamBroadcast.stream, - ); - - AppRequestsToHub.appRequestsToHubStreamController - .add(ClientStatusRequests(sendingType: SendingType.firstConnection)); - - HubRequestsToApp.hubRequestsStreamBroadcast.add(response); - } catch (e) { - logger.e('Caught error while stream with hub\n$e'); - await channel?.shutdown(); - } - } - - /// Get Hub computer and software info - static Future getHubCompInfo( - String addressToHub, - int hubPort, - CompHubInfo compHubInfo, - ) async { - // channel = await _createCbjHubClient(addressToHub, hubPort); - // stub = CbjHubClient(channel!); - - try { - return await stub!.getCompHubInfo(compHubInfo); - } catch (e) { - logger.e('Caught error while trying to get Hub comp info\n$e'); - await channel?.shutdown(); - } - return null; - } - - static Future _createCbjHubClient( - String deviceIp, - int hubPort, - ) async { - await channel?.shutdown(); - return ClientChannel( - deviceIp, - port: hubPort, - options: const ChannelOptions(credentials: ChannelCredentials.insecure()), - ); - } -} - -/// Requests and updates from hub to the app -class HubRequestsToApp { - /// Stream of the requests from the hub - /// Broadcast can be listen multiple times - static StreamGroup hubRequestsStreamBroadcast = - StreamGroup.broadcast(); - - static bool boolListenWorking = false; - - /// Controller can be inserted multiple time - static final hubRequestsStreamController = - StreamController(); - - static Future listenToApp() async { - if (boolListenWorking) { - return; - } - boolListenWorking = true; - hubRequestsStreamBroadcast.add(hubRequestsStreamController.stream); - } -} - -/// App requests for the hub to execute -class AppRequestsToHub { - /// Stream controller of the app request for the hub - - static StreamGroup appRequestsToHubStreamBroadcast = - StreamGroup.broadcast(); - - static bool boolListenWorking = false; - - static final appRequestsToHubStreamController = - StreamController(); - - static Future listenToApp() async { - if (boolListenWorking) { - return; - } - boolListenWorking = true; - appRequestsToHubStreamBroadcast - .add(appRequestsToHubStreamController.stream); - } -} diff --git a/lib/infrastructure/hub_client/hub_client_demo.dart b/lib/infrastructure/hub_client/hub_client_demo.dart deleted file mode 100644 index a47b9ba3f..000000000 --- a/lib/infrastructure/hub_client/hub_client_demo.dart +++ /dev/null @@ -1,603 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; - -import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; -import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; -import 'package:cbj_integrations_controller/domain/scene/value_objects_scene_cbj.dart'; -import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_value_objects.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_value_objects.dart'; -import 'package:cbj_integrations_controller/utils.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; - -class HubClientDemo { - /// Creates a stream with the Hub - static Future createStreamWithHub() async { - try { - await firstConnection(); - } catch (e) { - logger.e('Error in demo Hub\n$e'); - } - } - - static Future firstConnection() async { - for (final RequestsAndStatusFromHub roomRequest in getAllRooms()) { - HubRequestsToApp.hubRequestsStreamController.add(roomRequest); - } - - for (final RequestsAndStatusFromHub devicesRequest in getAllDevices()) { - HubRequestsToApp.hubRequestsStreamController.add(devicesRequest); - } - - for (final RequestsAndStatusFromHub sceneRequest in getAllScenes()) { - HubRequestsToApp.hubRequestsStreamController.add(sceneRequest); - } - } - - static List getAllRooms() { - final List roomsList = []; - - const SendingType sendingTypeRoom = SendingType.roomType; - - /// Discovered Room - - final RoomEntity allRemoteCommandsRoomDiscovered = RoomEntity( - uniqueId: - RoomUniqueId.fromUniqueString('00000000-0000-0000-0000-000000000000'), - cbjEntityName: RoomDefaultName('Discovered'), - roomTypes: RoomTypes(const []), - roomDevicesId: - RoomDevicesId(const ['65d84b10-434d-11ed-817a-7d350fb52f91']), - roomScenesId: RoomScenesId(const []), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - background: RoomBackground( - 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', - ), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubRoomDiscovered = - RequestsAndStatusFromHub( - sendingType: sendingTypeRoom, - allRemoteCommands: jsonEncode( - allRemoteCommandsRoomDiscovered.toInfrastructure().toJson(), - ), - ); - roomsList.add(requestsAndStatusFromHubRoomDiscovered); - - /// Guy Room - - final RoomEntity allRemoteCommandsRoomGuy = RoomEntity( - uniqueId: - RoomUniqueId.fromUniqueString('23deb7f0-4193-11ed-9d1c-5747056d7848'), - cbjEntityName: RoomDefaultName('Guy Room'), - roomTypes: RoomTypes([ - AreaPurposesTypes.bedroom.value.toString(), - AreaPurposesTypes.studyRoom.value.toString(), - AreaPurposesTypes.workRoom.value.toString(), - AreaPurposesTypes.videoGames.value.toString(), - ]), - roomDevicesId: RoomDevicesId(const [ - 'a31523m6-463s-32ge-7426-g33c642r7m25', - 'c90137f2-419b-11ed-8246-e17a279f4d89', - '96386cd0-419b-11ed-8246-e17a279f4d89', - ]), - roomScenesId: - RoomScenesId(const ['01bd6880-419b-11ed-af10-f75196d26a5e']), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - background: RoomBackground( - 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', - ), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubRoomGuy = - RequestsAndStatusFromHub( - sendingType: sendingTypeRoom, - allRemoteCommands: jsonEncode( - allRemoteCommandsRoomGuy.toInfrastructure().toJson(), - ), - ); - roomsList.add(requestsAndStatusFromHubRoomGuy); - - /// Out Side Room - - final RoomEntity allRemoteCommandsRoomOutSide = RoomEntity( - uniqueId: - RoomUniqueId.fromUniqueString('38b45780-419c-11ed-bce9-8dc09da0062f'), - cbjEntityName: RoomDefaultName('Outside'), - roomTypes: RoomTypes([ - AreaPurposesTypes.bedroom.value.toString(), - AreaPurposesTypes.studyRoom.value.toString(), - AreaPurposesTypes.workRoom.value.toString(), - AreaPurposesTypes.livingRoom.value.toString(), - ]), - roomDevicesId: - RoomDevicesId(const ['gcvweg3y-bv2s-cvwe-bdmf-7h4f3f2dw2d1']), - roomScenesId: RoomScenesId(const []), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - background: RoomBackground( - 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', - ), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubRoomOutSide = - RequestsAndStatusFromHub( - sendingType: sendingTypeRoom, - allRemoteCommands: jsonEncode( - allRemoteCommandsRoomOutSide.toInfrastructure().toJson(), - ), - ); - roomsList.add(requestsAndStatusFromHubRoomOutSide); - - /// Out Side Room - - final RoomEntity allRemoteCommandsRoomAmi = RoomEntity( - uniqueId: - RoomUniqueId.fromUniqueString('gai23tds-f3t7-vxa2-dvnn-hykkjty8567d'), - cbjEntityName: RoomDefaultName('Ami Room'), - roomTypes: RoomTypes([ - AreaPurposesTypes.bedroom.value.toString(), - AreaPurposesTypes.studyRoom.value.toString(), - AreaPurposesTypes.workRoom.value.toString(), - AreaPurposesTypes.livingRoom.value.toString(), - ]), - roomDevicesId: RoomDevicesId(const [ - '7189ed76-4351-11ed-b249-63fd7e165c16', - 'sfds344t-sdf3-fd3d-24s4-bd2sdf3n5rfd', - 'wfdsg2w6-fgde-234s-vbz2-b234jmgvbfd6', - ]), - roomScenesId: RoomScenesId(const []), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - background: RoomBackground( - 'https://images.pexels.com/photos/1457842/pexels-photo-1457842.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', - ), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubRoomAmi = - RequestsAndStatusFromHub( - sendingType: sendingTypeRoom, - allRemoteCommands: jsonEncode( - allRemoteCommandsRoomAmi.toInfrastructure().toJson(), - ), - ); - roomsList.add(requestsAndStatusFromHubRoomAmi); - - return roomsList; - } - - static List getAllDevices() { - final List devicesList = []; - - const SendingType sendingTypeDevice = SendingType.entityType; - - /// Guy Blinds - - final GenericBlindsDE allRemoteCommandsBlinds = GenericBlindsDE( - uniqueId: - CoreUniqueId.fromUniqueString('96386cd0-419b-11ed-8246-e17a279f4d89'), - entityUniqueId: EntityUniqueId('63b298'), - deviceVendor: - DeviceVendor(VendorsAndServices.switcherSmartHome.toString()), - cbjEntityName: CbjEntityName('Guy Blinds'), - entityOriginalName: EntityOriginalName('Guy Blinds'), - deviceOriginalName: DeviceOriginalName('Guy Blinds'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('switcher'), - senderDeviceModel: - DeviceSenderDeviceModel('SwitcherDevicesTypes.switcherRunner'), - senderId: DeviceSenderId.fromUniqueString( - '94edb282-434a-11ed-bd96-f573a00b65aa', - ), - compUuid: DeviceCompUuid('34asdfrsd23gggg'), - blindsSwitchState: - GenericBlindsSwitchState(EntityActions.stop.toString()), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('n5sdf1sf-df53-v2sd-ge46-hhjlywawq166'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubBlinds = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsBlinds), - ); - - devicesList.add(requestsAndStatusFromHubBlinds); - - /// Guy Ceiling Button - - final GenericSwitchDE allRemoteCommandsButton = GenericSwitchDE( - uniqueId: - CoreUniqueId.fromUniqueString('c90137f2-419b-11ed-8246-e17a279f4d89'), - entityUniqueId: EntityUniqueId('67600068c44f33f5b515'), - deviceVendor: DeviceVendor(VendorsAndServices.tuyaSmart.toString()), - cbjEntityName: CbjEntityName('Guy Ceiling Button'), - entityOriginalName: EntityOriginalName('Guy Ceiling Button'), - deviceOriginalName: DeviceOriginalName('Guy Ceiling Button'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('switcher'), - senderDeviceModel: DeviceSenderDeviceModel('Cloud'), - senderId: DeviceSenderId.fromUniqueString( - '90d20fc3-434a-11ed-bd96-f573a00b65aa', - ), - compUuid: DeviceCompUuid('34asdfrsd23gggg'), - switchState: GenericSwitchSwitchState(EntityActions.on.toString()), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('b0gaseh2-u7f4-1g42-vdf2-dfnertaku3fs'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubButton = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsButton), - ); - devicesList.add(requestsAndStatusFromHubButton); - - /// Guy Button 2 - - final GenericSwitchDE allRemoteCommandsButton2 = GenericSwitchDE( - uniqueId: - CoreUniqueId.fromUniqueString('a31523m6-463s-32ge-7426-g33c642r7m25'), - entityUniqueId: EntityUniqueId('67600068c44f33f5b515'), - deviceVendor: DeviceVendor(VendorsAndServices.tuyaSmart.toString()), - cbjEntityName: CbjEntityName('Guy Bedroom Button'), - entityOriginalName: EntityOriginalName('Guy Bedroom Button'), - deviceOriginalName: DeviceOriginalName('Guy Bedroom Button'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('switcher'), - senderDeviceModel: DeviceSenderDeviceModel('Cloud'), - senderId: DeviceSenderId.fromUniqueString( - '90d20fc3-434a-11ed-bd96-f573a00b65aa', - ), - compUuid: DeviceCompUuid('34asdfrsd23gggg'), - switchState: GenericSwitchSwitchState(EntityActions.on.toString()), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('654wdf2u-rge2-ffh2-gn22-rthweru521rs'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubButton2 = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsButton2), - ); - devicesList.add(requestsAndStatusFromHubButton2); - - /// Boiler - - final GenericBoilerDE allRemoteCommandsBoiler = GenericBoilerDE( - uniqueId: - CoreUniqueId.fromUniqueString('65d84b10-434d-11ed-817a-7d350fb52f91'), - entityUniqueId: EntityUniqueId('65fd2f'), - deviceVendor: - DeviceVendor(VendorsAndServices.switcherSmartHome.toString()), - cbjEntityName: CbjEntityName('Boiler'), - entityOriginalName: EntityOriginalName('Boiler'), - deviceOriginalName: DeviceOriginalName('Boiler'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('switcher'), - senderDeviceModel: - DeviceSenderDeviceModel('SwitcherDevicesTypes.switcherV2Esp'), - senderId: DeviceSenderId.fromUniqueString( - '65d84b11-434d-11ed-817a-7d350fb52f91', - ), - compUuid: DeviceCompUuid('34asdfrsd23gggg'), - boilerSwitchState: GenericBoilerSwitchState(EntityActions.off.toString()), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('id2erfdd-g34a-uhj5-fdfa-sdf5y3wsdfhs'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubBoiler = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsBoiler), - ); - devicesList.add(requestsAndStatusFromHubBoiler); - - /// RGBLight - - final GenericRgbwLightDE allRemoteCommandsRgbLight = GenericRgbwLightDE( - uniqueId: - CoreUniqueId.fromUniqueString('7189ed76-4351-11ed-b249-63fd7e165c16'), - entityUniqueId: EntityUniqueId('bf4bccdaf68347e31dhiut'), - deviceVendor: DeviceVendor(VendorsAndServices.tuyaSmart.toString()), - cbjEntityName: CbjEntityName('Dining Room Ceiling'), - entityOriginalName: EntityOriginalName('Dining Room Ceiling'), - deviceOriginalName: DeviceOriginalName('Dining Room Ceiling'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('tuya_smart'), - senderDeviceModel: DeviceSenderDeviceModel('1SE'), - senderId: DeviceSenderId.fromUniqueString( - '7189ed77-4351-11ed-b249-63fd7e165c16', - ), - compUuid: DeviceCompUuid('34asdfrsd23gggg'), - lightSwitchState: - GenericRgbwLightSwitchState(EntityActions.off.toString()), - lightBrightness: GenericRgbwLightBrightness('100'), - lightColorAlpha: GenericRgbwLightColorAlpha('1.0'), - lightColorHue: GenericRgbwLightColorHue('0.0'), - lightColorSaturation: GenericRgbwLightColorSaturation('1.0'), - lightColorTemperature: GenericRgbwLightColorTemperature('8129'), - lightColorValue: GenericRgbwLightColorValue('1.0'), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('sd3fgbns-64as-1gd2-gfdw-dgghks325as6'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubRgbLight = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsRgbLight), - ); - devicesList.add(requestsAndStatusFromHubRgbLight); - - /// RGBLight - - final GenericDimmableLightDE allRemoteCommandsDimmableLight1 = - GenericDimmableLightDE( - uniqueId: - CoreUniqueId.fromUniqueString('sfds344t-sdf3-fd3d-24s4-bd2sdf3n5rfd'), - entityUniqueId: EntityUniqueId('dn2fs1sgnxzzx34sh53qdf'), - deviceVendor: DeviceVendor(VendorsAndServices.lifx.toString()), - cbjEntityName: CbjEntityName('Dining Room Stove'), - entityOriginalName: EntityOriginalName('Dining Room Light 1'), - deviceOriginalName: DeviceOriginalName('Dining Room Light 1'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('lifx'), - senderDeviceModel: DeviceSenderDeviceModel('1SE'), - senderId: DeviceSenderId.fromUniqueString( - 'askf3gd7-nb21-fg2d-bvw9-xcbsd24sdgd6', - ), - compUuid: DeviceCompUuid('sn45sd1fcn5532d'), - lightSwitchState: - GenericDimmableLightSwitchState(EntityActions.off.toString()), - lightBrightness: GenericDimmableLightBrightness('100'), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('dgh4nsdg-fd2d-df32-vn4g-dfgw2dvvnrrg'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubDimmableLight1 = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: DeviceHelper.convertDomainToJsonString( - allRemoteCommandsDimmableLight1, - ), - ); - devicesList.add(requestsAndStatusFromHubDimmableLight1); - - final GenericDimmableLightDE allRemoteCommandsDimmableLight2 = - GenericDimmableLightDE( - uniqueId: - CoreUniqueId.fromUniqueString('gcvweg3y-bv2s-cvwe-bdmf-7h4f3f2dw2d1'), - entityUniqueId: EntityUniqueId('4gj76jykeg3fsdf2dsq11f'), - deviceVendor: DeviceVendor(VendorsAndServices.lifx.toString()), - cbjEntityName: CbjEntityName('Ami Room Ceiling'), - entityOriginalName: EntityOriginalName('Ami Workshop Light'), - deviceOriginalName: DeviceOriginalName('Ami Workshop Light'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('lifx'), - senderDeviceModel: DeviceSenderDeviceModel('1SE'), - senderId: DeviceSenderId.fromUniqueString( - 'f23gg2d2-h6j7-k8ky-6ugh-6t574ty47yj5', - ), - compUuid: DeviceCompUuid('dg23esbh4eghrer'), - lightSwitchState: - GenericDimmableLightSwitchState(EntityActions.off.toString()), - lightBrightness: GenericDimmableLightBrightness('100'), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('nbfsgsdf-34f3-631w-125f-324f23567731'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubDimmableLight2 = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: DeviceHelper.convertDomainToJsonString( - allRemoteCommandsDimmableLight2, - ), - ); - devicesList.add(requestsAndStatusFromHubDimmableLight2); - - /// Light - - final GenericLightDE allRemoteCommandsLight = GenericLightDE( - uniqueId: - CoreUniqueId.fromUniqueString('wfdsg2w6-fgde-234s-vbz2-b234jmgvbfd6'), - entityUniqueId: EntityUniqueId('cb3rdfh2ttgl9dgbvnsudt'), - deviceVendor: DeviceVendor(VendorsAndServices.espHome.toString()), - cbjEntityName: CbjEntityName('Dining Room Light 2'), - entityOriginalName: EntityOriginalName('Dining Room Light 2'), - deviceOriginalName: DeviceOriginalName('Dining Room Light 2'), - entityStateGRPC: EntityState(EntityStateGRPC.ack.toString()), - stateMassage: DeviceStateMassage('Hello World'), - senderDeviceOs: DeviceSenderDeviceOs('espHome'), - senderDeviceModel: DeviceSenderDeviceModel('esp8266'), - senderId: DeviceSenderId.fromUniqueString( - 'ffb3rg2s-cvns-awre-bmkp-yityueyertbe', - ), - compUuid: DeviceCompUuid('erbvnr34yh4627i'), - lightSwitchState: GenericLightSwitchState(EntityActions.off.toString()), - powerConsumption: DevicePowerConsumption('0'), - deviceUniqueId: DeviceUniqueId('deviceUniqueId'), - devicePort: DevicePort('devicePort'), - deviceLastKnownIp: DeviceLastKnownIp('deviceLastKnownIp'), - deviceHostName: DeviceHostName('deviceHostName'), - deviceMdns: DeviceMdns('deviceMdns'), - devicesMacAddress: DevicesMacAddress('devicesMacAddress'), - entityKey: EntityKey('entityKey'), - requestTimeStamp: RequestTimeStamp('requestTimeStamp'), - lastResponseFromDeviceTimeStamp: - LastResponseFromDeviceTimeStamp('lastResponseFromDeviceTimeStamp'), - deviceCbjUniqueId: - CoreUniqueId.fromUniqueString('sgeryjmn-gfn3-bf3v-et24-fvd22445jng3'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubLight = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: - DeviceHelper.convertDomainToJsonString(allRemoteCommandsLight), - ); - devicesList.add(requestsAndStatusFromHubLight); - - return devicesList; - } - - static List getAllScenes() { - final List scenesList = []; - - const SendingType sendingTypeDevice = SendingType.sceneType; - - /// Study Scene - - final SceneCbjEntity allRemoteCommandsSceneOpen = SceneCbjEntity( - uniqueId: - UniqueId.fromUniqueString('01bd6880-419b-11ed-af10-f75196d26a5e'), - name: SceneCbjName('Study Scene'), - backgroundColor: SceneCbjBackgroundColor('0xFFFF9800'), - nodeRedFlowId: SceneCbjNodeRedFlowId('6b63068c3c970eeb'), - automationString: SceneCbjAutomationString('[]'), - firstNodeId: SceneCbjFirstNodeId('3f1a9440-41a1-11ed-8b6a-5f136f4fe196'), - iconCodePoint: SceneCbjIconCodePoint(null), - image: SceneCbjBackgroundImage(null), - lastDateOfExecute: SceneCbjLastDateOfExecute(null), - stateMassage: SceneCbjStateMassage(null), - senderDeviceOs: SceneCbjSenderDeviceOs(null), - senderDeviceModel: SceneCbjSenderDeviceModel(null), - senderId: SceneCbjSenderId(null), - compUuid: SceneCbjCompUuid(null), - entityStateGRPC: SceneCbjDeviceStateGRPC('waitingInComp'), - ); - - final RequestsAndStatusFromHub requestsAndStatusFromHubSceneOpen = - RequestsAndStatusFromHub( - sendingType: sendingTypeDevice, - allRemoteCommands: jsonEncode( - allRemoteCommandsSceneOpen.toInfrastructure().toJson(), - ), - ); - - scenesList.add(requestsAndStatusFromHubSceneOpen); - - return scenesList; - } - - /// Get Hub computer and software info - static Future getHubCompInfo( - String addressToHub, - int hubPort, - CompHubInfo compHubInfo, - ) async { - return null; - } -} diff --git a/lib/infrastructure/hub_client/hub_connection_repository.dart b/lib/infrastructure/hub_client/hub_connection_repository.dart index 458945190..062d239e5 100644 --- a/lib/infrastructure/hub_client/hub_connection_repository.dart +++ b/lib/infrastructure/hub_client/hub_connection_repository.dart @@ -1,19 +1,19 @@ import 'dart:async'; import 'dart:io'; +import 'package:cbj_integrations_controller/domain/hub/hub_entity.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_value_objects.dart'; import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.dart'; import 'package:cbj_integrations_controller/domain/local_db/local_db_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client_demo.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_dtos.dart'; import 'package:cbj_integrations_controller/utils.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; -import 'package:cybear_jinni/domain/hub/hub_entity.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; -import 'package:cybear_jinni/domain/hub/hub_value_objects.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client_demo.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_dtos.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart' show kIsWeb; diff --git a/lib/infrastructure/hub_client/hub_dtos.dart b/lib/infrastructure/hub_client/hub_dtos.dart deleted file mode 100644 index 9a1651d57..000000000 --- a/lib/infrastructure/hub_client/hub_dtos.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:cybear_jinni/domain/hub/hub_entity.dart'; -import 'package:cybear_jinni/domain/hub/hub_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'hub_dtos.freezed.dart'; -part 'hub_dtos.g.dart'; - -@freezed -abstract class HubDtos implements _$HubDtos { - factory HubDtos({ - // @JsonKey(includeFromJson: true) - - required String hubNetworkBssid, - required String networkName, - required String lastKnownIp, - // required ServerTimestampConverter() FieldValue serverTimeStamp, - }) = _HubDtos; - - HubDtos._(); - - factory HubDtos.fromDomain(HubEntity hubDE) { - return HubDtos( - hubNetworkBssid: hubDE.hubNetworkBssid.getOrCrash(), - networkName: hubDE.networkName.getOrCrash(), - lastKnownIp: hubDE.lastKnownIp.getOrCrash(), - ); - } - - factory HubDtos.fromJson(Map json) => - _$HubDtosFromJson(json); - - final String deviceDtoClassInstance = (HubDtos).toString(); - - HubEntity toDomain() { - return HubEntity( - hubNetworkBssid: HubNetworkBssid(hubNetworkBssid), - networkName: HubNetworkName(networkName), - lastKnownIp: HubNetworkIp(lastKnownIp), - ); - } -} - -// class ServerTimestampConverter implements JsonConverter { -// const ServerTimestampConverter(); -// -// @override -// FieldValue fromJson(Object json) { -// return FieldValue.serverTimestamp(); -// } -// -// @override -// Object toJson(FieldValue fieldValue) => fieldValue; -// } diff --git a/lib/infrastructure/hub_client/hub_requests_routing.dart b/lib/infrastructure/hub_client/hub_requests_routing.dart index 98936a49d..5e09daee1 100644 --- a/lib/infrastructure/hub_client/hub_requests_routing.dart +++ b/lib/infrastructure/hub_client/hub_requests_routing.dart @@ -19,12 +19,12 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv_device/generic_smart_tv_device_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_device_dtos.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cbj_integrations_controller/infrastructure/room/room_entity_dtos.dart'; import 'package:cbj_integrations_controller/infrastructure/scenes/scene_cbj_dtos.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/infrastructure/objects/enums_cbj.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/utils.dart'; @@ -57,9 +57,11 @@ class HubRequestRouting { // requestsFromHubSubscription = null; connectivityChangedStream = null; - requestsFromHubSubscription = HubRequestsToApp - .hubRequestsStreamBroadcast.stream - .listen((RequestsAndStatusFromHub requestsAndStatusFromHub) { + requestsFromHubSubscription = HubRequestsToApp.streamRequestsToApp.stream + .listen((dynamic requestsAndStatusFromHub) { + if (requestsAndStatusFromHub is! RequestsAndStatusFromHub) { + return; + } if (requestsAndStatusFromHub.sendingType == SendingType.entityType) { navigateDeviceRequest(requestsAndStatusFromHub.allRemoteCommands); } else if (requestsAndStatusFromHub.sendingType == SendingType.roomType) { @@ -73,7 +75,7 @@ class HubRequestRouting { '${requestsAndStatusFromHub.sendingType}', ); } - }); + }) as StreamSubscription?; requestsFromHubSubscription?.onError((error) async { if (error is GrpcError && error.code == 1) { logger.t('Hub have been disconnected'); diff --git a/lib/infrastructure/mqtt/mqtt.dart b/lib/infrastructure/mqtt/mqtt.dart index 03af85e95..f8a1120b1 100644 --- a/lib/infrastructure/mqtt/mqtt.dart +++ b/lib/infrastructure/mqtt/mqtt.dart @@ -2,7 +2,7 @@ import 'package:cbj_integrations_controller/domain/mqtt_server/i_mqtt_server_rep import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; import 'package:mqtt_client/src/observable/src/records.dart'; @@ -48,7 +48,7 @@ class MqttServerRepository extends IMqttServerRepository { Future postSmartDeviceToAppMqtt({ required DeviceEntityAbstract entityFromTheHub, }) async { - HubRequestsToApp.hubRequestsStreamController.sink.add( + HubRequestsToApp.streamRequestsToApp.sink.add( RequestsAndStatusFromHub( sendingType: SendingType.entityType, allRemoteCommands: @@ -58,8 +58,9 @@ class MqttServerRepository extends IMqttServerRepository { } @override - Future postToAppMqtt( - {required DeviceEntityAbstract entityFromTheHub}) async {} + Future postToAppMqtt({ + required DeviceEntityAbstract entityFromTheHub, + }) async {} @override Future postToHubMqtt({ @@ -112,7 +113,8 @@ class MqttServerRepository extends IMqttServerRepository { @override Stream>> streamOfChosenSubscription( - String topicPath) { + String topicPath, + ) { // TODO: implement streamOfChosenSubscription throw UnimplementedError(); } diff --git a/lib/infrastructure/phone_hub/phone_hub.dart b/lib/infrastructure/phone_hub/phone_hub.dart index d96eb8876..3e6f3405b 100644 --- a/lib/infrastructure/phone_hub/phone_hub.dart +++ b/lib/infrastructure/phone_hub/phone_hub.dart @@ -6,7 +6,7 @@ import 'package:cbj_integrations_controller/infrastructure/devices/helper_method import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:network_tools/network_tools.dart'; @@ -42,7 +42,7 @@ class PhoneHub { logger.i('mdnsDevicesTemp is empty'); } for (final ActiveHost activeHost in mdnsDevicesTemp) { - print('activeHost $activeHost'); + logger.i('activeHost $activeHost'); CompaniesConnectorConjector.setMdnsDeviceByCompany(activeHost); // } @@ -51,7 +51,7 @@ class PhoneHub { logger.i('pingableDevicesTemp is empty'); } for (final ActiveHost activeHost in pingableDevicesTemp) { - print('activeHost2 $activeHost'); + logger.i('activeHost2 $activeHost'); CompaniesConnectorConjector.setHostNameDeviceByCompany( activeHost: activeHost, ); @@ -59,7 +59,7 @@ class PhoneHub { } } - startListen() { + void startListen() { phoneAsHub = true; CompaniesConnectorConjector.updateAllDevicesReposWithDeviceChanges( AppRequestsToHub.appRequestsToHubStreamController.stream @@ -67,7 +67,7 @@ class PhoneHub { if (!phoneAsHub) { return ''; } - dynamic dtosEntity = + final dynamic dtosEntity = DeviceHelperMethods.clientStatusRequestsToItsDtosType( clientStatusRequests, ); diff --git a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart b/lib/infrastructure/remote_pipes/remote_pipes_repository.dart index 858e205a9..523c65d09 100644 --- a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart +++ b/lib/infrastructure/remote_pipes/remote_pipes_repository.dart @@ -2,10 +2,10 @@ import 'dart:convert'; import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/domain/remote_pipes/i_remote_pipes_repository.dart'; import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_dtos.dart'; import 'package:dartz/dartz.dart'; diff --git a/lib/infrastructure/room/room_repository.dart b/lib/infrastructure/room/room_repository.dart index 57b61fa4f..ef46d8fda 100644 --- a/lib/infrastructure/room/room_repository.dart +++ b/lib/infrastructure/room/room_repository.dart @@ -6,7 +6,7 @@ import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; +import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; diff --git a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart index 7a800aa8f..00aa2c9ba 100644 --- a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart +++ b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart @@ -130,10 +130,6 @@ class SecurityBearConnectionRepository logger.w('Cant check connectivity this is probably PC, error\n$e'); } - final String? wifiBSSID = await NetworkInfo().getWifiBSSID(); - final String? wifiBSSIDWithoutLastNumber = - wifiBSSID?.substring(0, wifiBSSID.lastIndexOf(':')); - // Check if you are connected to the home local network for direct // communication with the SecurityBear. // This block can be false also if user does not improve some permissions diff --git a/lib/infrastructure/software_info/software_info_repository.dart b/lib/infrastructure/software_info/software_info_repository.dart index 844f47719..4b137d7c4 100644 --- a/lib/infrastructure/software_info/software_info_repository.dart +++ b/lib/infrastructure/software_info/software_info_repository.dart @@ -1,10 +1,10 @@ import 'dart:io'; +import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_app_server/proto_gen_date.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_app_server/protoc_as_dart/cbj_app_connections.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/proto_gen_date.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; diff --git a/lib/infrastructure/user/user_repository.dart b/lib/infrastructure/user/user_repository.dart index dd7516c0e..e5b6fa575 100644 --- a/lib/infrastructure/user/user_repository.dart +++ b/lib/infrastructure/user/user_repository.dart @@ -8,7 +8,6 @@ import 'package:cybear_jinni/domain/user/i_user_repository.dart'; import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart'; import 'package:cybear_jinni/infrastructure/user/user_dtos.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; import 'package:kt_dart/kt.dart'; @@ -17,10 +16,7 @@ class UserRepository implements IUserRepository { @override Future> create(UserEntity userEntity) async { try { - // final userCollec = await _firestore.usersCollection(); - final userDtos = UserDtos.fromDomain(userEntity); - - // await userCollec.doc(userDtos.id.toString()).set(userDtos.toJson()); + UserDtos.fromDomain(userEntity); return right(unit); } on PlatformException catch (e) { @@ -38,7 +34,7 @@ class UserRepository implements IUserRepository { try { // final userCollec = await _firestore.usersCollection(); - final String userId = (await IAuthFacade.instance.getSignedInUser()) + (await IAuthFacade.instance.getSignedInUser()) .getOrElse(() => throw NotAuthenticatedError()) .id .getOrCrash(); @@ -73,7 +69,6 @@ class UserRepository implements IUserRepository { // final usersCollection = await _firestore.usersCollection(); // final homeCollection = await _firestore.homeCollection(); - final String userId = userEntity.id!.getOrCrash()!; final String homeId = allHomesOfUserEntity.id!.getOrCrash()!; // final userInHomeRef = @@ -84,8 +79,7 @@ class UserRepository implements IUserRepository { // return left(const HomeUserFailures.homeDoesNotExist()); // } // - final AllHomesOfUserDtos homeUserDtos = - AllHomesOfUserDtos.fromDomain(allHomesOfUserEntity); + AllHomesOfUserDtos.fromDomain(allHomesOfUserEntity); // // await usersCollection // .doc(userId) @@ -143,7 +137,7 @@ class UserRepository implements IUserRepository { try { // final homeCollection = await _firestore.homeCollection(); - final String userId = (await IAuthFacade.instance.getSignedInUser()) + (await IAuthFacade.instance.getSignedInUser()) .getOrElse(() => throw NotAuthenticatedError()) .id .getOrCrash(); diff --git a/lib/infrastructure/vendors/vendor_helper.dart b/lib/infrastructure/vendors/vendor_helper.dart deleted file mode 100644 index dc9ffd9ba..000000000 --- a/lib/infrastructure/vendors/vendor_helper.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'dart:convert'; - -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/login_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_vendors_login/generic_login_abstract/login_entity_dto_abstract.dart'; - -class VendorHelper { - /// Dto to json - static Map convertDtoToJson( - LoginEntityDtoAbstract loginEntityDto, - ) { - return loginEntityDto.toJson(); - } - - /// json to Dto - static LoginEntityDtoAbstract convertJsonToDto(Map json) { - return LoginEntityDtoAbstract.fromJson(json); - } - - /// json to json string - static String convertJsonToJsonString(Map json) { - return jsonEncode(json); - } - - /// string json to json - static Map convertJsonStringToJson(String jsonString) { - return jsonDecode(jsonString) as Map; - } - - /// Device entity to dto - static LoginEntityDtoAbstract convertDomainToDto( - LoginEntityAbstract loginEntity, - ) { - return loginEntity.toInfrastructure(); - } - - /// Dto to login entity - static LoginEntityAbstract convertDtoToDomain( - LoginEntityDtoAbstract loginEntityDto, - ) { - return loginEntityDto.toDomain(); - } - - // Extras methods - - static String convertDtoToJsonString( - LoginEntityDtoAbstract loginEntityDto, - ) { - return convertJsonToJsonString(convertDtoToJson(loginEntityDto)); - } - - static LoginEntityAbstract convertJsonStringToDomain(String jsonString) { - return convertDtoToDomain( - convertJsonToDto(convertJsonStringToJson(jsonString)), - ); - } - - static String convertDomainToJsonString(LoginEntityAbstract loginEntity) { - return convertJsonToJsonString( - convertDtoToJson(convertDomainToDto(loginEntity)), - ); - } -} diff --git a/lib/infrastructure/vendors/vendors_repository.dart b/lib/infrastructure/vendors/vendors_repository.dart deleted file mode 100644 index a310a10ef..000000000 --- a/lib/infrastructure/vendors/vendors_repository.dart +++ /dev/null @@ -1,288 +0,0 @@ -import 'package:cbj_integrations_controller/domain/vendors/esphome_login/generic_esphome_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/ewelink_login/generic_ewelink_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/lifx_login/generic_lifx_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/login_entity_abstract.dart'; -import 'package:cbj_integrations_controller/domain/vendors/tuya_login/generic_tuya_login_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_value_objects.dart'; -import 'package:cbj_integrations_controller/domain/vendors/xiaomi_mi_login/generic_xiaomi_mi_login_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/infrastructure/hub_client/hub_client.dart'; -import 'package:cybear_jinni/infrastructure/vendors/vendor_helper.dart'; -import 'package:dartz/dartz.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -@LazySingleton(as: IVendorsRepository) -class VendorsRepository implements IVendorsRepository { - @override - Future>> getVendors() async { - final List vendorsWithIcons = []; - - // Add icons to supported vendors and services - for (final VendorsAndServices vendorsAndServices - in VendorsAndServices.values) { - final String vendorName = vendorsAndServices.name; - if (vendorName == - VendorsAndServices.vendorsAndServicesNotSupported.name || - vendorName == VendorsAndServices.miHome.name || - vendorName == VendorsAndServices.sonoffDiy.name || - vendorName == VendorsAndServices.ikea.name || - vendorName == VendorsAndServices.wink.name || - vendorName == VendorsAndServices.lg.name || - vendorName == VendorsAndServices.spotify.name || - vendorName == VendorsAndServices.homeAssistant.name || - vendorName == VendorsAndServices.yeelink.name || - vendorName == VendorsAndServices.xiaomi.name || - vendorName == VendorsAndServices.xiaomiMi.name || - vendorName == VendorsAndServices.wiz.name || - vendorName == VendorsAndServices.switchBot.name || - vendorName == VendorsAndServices.somfy.name || - vendorName == VendorsAndServices.tuyaSmart.name || - vendorName == VendorsAndServices.smartLife.name || - vendorName == VendorsAndServices.jinvooSmart.name || - vendorName == VendorsAndServices.cbjDeviceSmartEntity.name || - vendorName == VendorsAndServices.sensibo.name || - vendorName == VendorsAndServices.aqara.name || - vendorName == VendorsAndServices.matter.name || - vendorName == VendorsAndServices.nest.name || - vendorName == VendorsAndServices.uniFi.name || - vendorName == VendorsAndServices.ring.name || - vendorName == VendorsAndServices.myQ.name || - vendorName == VendorsAndServices.wemo.name || - vendorName == VendorsAndServices.tpLink.name || - vendorName == VendorsAndServices.nuki.name || - vendorName == VendorsAndServices.homebridge.name || - vendorName == VendorsAndServices.homeKit.name || - vendorName == VendorsAndServices.twinkly.name || - vendorName == VendorsAndServices.samsung.name || - vendorName == VendorsAndServices.tizen.name || - vendorName == VendorsAndServices.zigbee.name || - vendorName == VendorsAndServices.zWave.name || - vendorName == VendorsAndServices.ffmpeg.name || - vendorName == VendorsAndServices.lightwaveRf.name || - vendorName == VendorsAndServices.cololight.name || - vendorName == VendorsAndServices.broadlink.name || - vendorName == VendorsAndServices.switchBee.name || - vendorName == VendorsAndServices.mycroft.name || - vendorName == VendorsAndServices.cyBearJinniAppSmartEntity.name || - vendorName == VendorsAndServices.securityBear.name || - vendorName == VendorsAndServices.jinniAssistant.name) { - continue; - } - VendorData v = vendorPlusImageFromVandorName(vendorName); - if (vendorName == VendorsAndServices.switcherSmartHome.name) { - v = v.copyWith(name: VendorName('Switcher')); - } - vendorsWithIcons.add(v); - } - return right(vendorsWithIcons.toImmutableList()); - } - - VendorData vendorPlusImageFromVandorName(String vendorName) { - final String vendorNameNoCapsOrSpaceOrUnderscore = - vendorName.toLowerCase().replaceAll(' ', '').replaceAll('_', ''); - - for (final VendorData vendor - in VendorsMocDataWithImages().getAllVendors().asList()) { - final String vendorNameNoLowerCaseOrSpaceOrUnderscore = vendor.name - .getOrCrash() - .toLowerCase() - .replaceAll(' ', '') - .replaceAll('_', ''); - - if (vendorNameNoLowerCaseOrSpaceOrUnderscore == - vendorNameNoCapsOrSpaceOrUnderscore) { - return vendor; - } - } - - return VendorData( - name: VendorName(vendorName), - image: - 'https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.seilevel.com%2Frequirements%2Fwp-content%2Fplugins%2Fstormhill_author_page%2Fimg%2Fimage-not-found.png&f=1&nofb=1', - ); - } - - @override - Future> loginWithLifx( - GenericLifxLoginDE login, - ) async { - return loginWithVendor(login); - } - - @override - Future> loginWithTuya( - GenericTuyaLoginDE login, - ) async { - return loginWithVendor(login); - } - - Future> loginWithVendor( - LoginEntityAbstract login, - ) async { - try { - final String loginDtoAsString = - VendorHelper.convertDomainToJsonString(login); - - final ClientStatusRequests clientStatusRequests = ClientStatusRequests( - allRemoteCommands: loginDtoAsString, - sendingType: SendingType.vendorLoginType, - ); - - AppRequestsToHub.appRequestsToHubStreamController - .add(clientStatusRequests); - return right(unit); - } catch (e) { - return left(const CoreLoginFailure.unexpected()); - } - } - - @override - Future> loginWithEspHome( - GenericEspHomeLoginDE login, - ) { - return loginWithVendor(login); - } - - @override - Future> loginWithXiaomiMi( - GenericXiaomiMiLoginDE login, - ) { - return loginWithVendor(login); - } - - @override - Future> loginWithEwelink( - GenericEwelinkLoginDE login, - ) { - return loginWithVendor(login); - } -} - -class VendorsMocDataWithImages { - KtList getAllVendors() { - return [ - VendorData( - name: VendorName('Tasmota'), - image: 'https://i.ibb.co/XZLGCRd/Tasmota-logo.png', - ), - VendorData( - name: VendorName('Xiaomi Mi'), - image: - 'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.designbust.com%2Fdownload%2F1629%2Fpng%2Fxiaomi_logo512.png&f=1&nofb=1', - ), - VendorData( - name: VendorName('Lifx'), - image: - 'https://play-lh.googleusercontent.com/k61DT9oYt_BPdzjAFokLY5e-He-YSl7-eZHeieaVO45XDAwQ6ebegsS_ZsQytca2zWM=s180', - ), - VendorData( - name: VendorName('Sonoff eWeLink'), - image: - 'https://play-lh.googleusercontent.com/nfDq8xm5ueWPIZswiRD8PxzjmFAmOBgByV1CpFfAhau1_D_XCP2jW0EZ3VMEtZwbVRk=s180', - ), - VendorData( - name: VendorName('SwitcherSmartHome'), - image: - 'https://play-lh.googleusercontent.com/8L6vVAT2cC78V622nxSznr7Mm_MgMsH25TopH-ZIm5HMwAHRy0qTX29FlHF6_kbBsQ=s180', - ), - VendorData( - name: VendorName('Sonoff'), - image: - 'https://play-lh.googleusercontent.com/nfDq8xm5ueWPIZswiRD8PxzjmFAmOBgByV1CpFfAhau1_D_XCP2jW0EZ3VMEtZwbVRk=s180', - ), - VendorData( - name: VendorName('MQTT'), - image: 'https://i.ibb.co/hfRhB0Q/mqtt-logo.png', - ), - VendorData( - name: VendorName('Tuya Smart'), - image: - 'https://play-lh.googleusercontent.com/KGM9NYnyox9TXwoaY3PKl1PfQ2rTPp1rnpNNtmlbgozJZykhZhGKsL3z9myoj4ccayLS=s180', - ), - VendorData( - name: VendorName('Smart Life'), - image: - 'https://play-lh.googleusercontent.com/Qrq9zB_-bWuAD0ETPeBRTsRHOSjmW_uzmexY5rF7wo2JeNc-oLuvsQSYdg0Uxsq6mkA=s180', - ), - VendorData( - name: VendorName('Jinvoo Smart'), - image: - 'https://play-lh.googleusercontent.com/ocFF7mcDTJzr1PXr6k4q1Q2-5xNFUVODqluwnD60DiTsHgTalrVTqi7kk0H8JnW7GLEv=s180', - ), - VendorData( - name: VendorName('Eufy'), - image: - 'https://play-lh.googleusercontent.com/kTVQJspUeisuM03rNaLjdexsqsdz3Eh7dGAiL1WE_32HPHTjZmCELzsyym2LW3dY5fM=s180', - ), - VendorData( - name: VendorName('Philips Hue'), - image: - 'https://play-lh.googleusercontent.com/FUlW6h3cACamheiCHH1cE67irohAZq_dJ92irK92cryKwHUtY6ZTSv5d041qPZ9UOt3n=s180', - ), - VendorData( - name: VendorName('Yeelight'), - image: - 'https://play-lh.googleusercontent.com/bteU9OSFF9z596eUOkGgM3XpWF2-b1VsKvmwWFitaI4qMwVPmx3lS09fHFDx8-CX3Q=s180', - ), - VendorData( - name: VendorName('ESPHome'), - image: 'https://i.ibb.co/W2YG23s/ESPHome-logo.png', - ), - VendorData( - name: VendorName('Ring'), - image: - 'https://play-lh.googleusercontent.com/fbIl2IKPAG4_3lNnwsi0qMBTJEgOsIwBUYzrs5_GIRYRBHov_a5eJ0bMxEUNMu67G4Ws=s180', - ), - VendorData( - name: VendorName('Google'), - image: - 'https://play-lh.googleusercontent.com/DKoidc0T3T1KvYC2stChcX9zwmjKj1pgmg3hXzGBDQXM8RG_7JjgiuS0CLOh8DUa7as=s180', - ), - VendorData( - name: VendorName('Ikea'), - image: - 'https://play-lh.googleusercontent.com/IFwqvqScIUpmiyp4dD4NwJuQ3D2Xa6xRkGLHtLcVNaBKrZ6048MsrRTZ7uaL76xKp4E=s180', - ), - VendorData( - name: VendorName('Wink'), - image: - 'https://play-lh.googleusercontent.com/cFGBLtsmWJGXcc6Nc_saGVz4d8bzxgA_VsCF1EoLYA_tlAcKOoPZD-RBABC8qho4j54=s180', - ), - VendorData( - name: VendorName('Shelly'), - image: - 'https://play-lh.googleusercontent.com/cwAyt0LIs4cyXSs2jr79xjAxsuq4KoBTZNq__gpeQvupH-8PElGn6kiddx8-WfG8wEPl=s180', - ), - VendorData( - name: VendorName('Jinvoo Smart'), - image: - 'https://play-lh.googleusercontent.com/ocFF7mcDTJzr1PXr6k4q1Q2-5xNFUVODqluwnD60DiTsHgTalrVTqi7kk0H8JnW7GLEv=s180', - ), - VendorData( - name: VendorName('Smart Life'), - image: - 'https://play-lh.googleusercontent.com/Qrq9zB_-bWuAD0ETPeBRTsRHOSjmW_uzmexY5rF7wo2JeNc-oLuvsQSYdg0Uxsq6mkA=s180', - ), - VendorData( - name: VendorName('HP'), - image: - 'https://play-lh.googleusercontent.com/UF16mldRKpQUUWhRZlDnT1FjkAjWSu9NXVBEDoTgScI_eo_6yEL0oKtc2-OvPXcG3PmN=s180', - ), - VendorData( - name: VendorName('CBJ Devices'), - image: - 'https://github.com/CyBear-Jinni/CBJ_Site/blob/master/assets/images/cbj_app_icon_no_bg.png?raw=true', - ), - VendorData( - name: VendorName('Google'), - image: - 'https://play-lh.googleusercontent.com/aFWiT2lTa9CYBpyPjfgfNHd0r5puwKRGj2rHpdPTNrz2N9LXgN_MbLjePd1OTc0E8Rl1=s180', - ), - ].toImmutableList(); - } -} diff --git a/lib/main.dart b/lib/main.dart index 9d9a1d93f..65cb65bbf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,36 +20,10 @@ import 'package:dartz/dartz.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:network_tools/network_tools.dart'; import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; -import 'package:rxdart/rxdart.dart'; - -/// Streams are created so that app can respond to notification-related events -/// since the plugin is initialised in the `main` function -final BehaviorSubject didReceiveLocalNotificationSubject = - BehaviorSubject(); - -final BehaviorSubject selectNotificationSubject = - BehaviorSubject(); - -const MethodChannel platform = MethodChannel('cybear_jinni/smart_home'); - -class ReceivedNotification { - ReceivedNotification({ - required this.id, - required this.title, - required this.body, - required this.payload, - }); - - final int? id; - final String? title; - final String? body; - final String? payload; -} Future main() async { RoomRepository(); diff --git a/lib/presentation/core/notifications.dart b/lib/presentation/core/notifications.dart index 18068b45b..775aff704 100644 --- a/lib/presentation/core/notifications.dart +++ b/lib/presentation/core/notifications.dart @@ -1,4 +1,3 @@ -import 'package:cybear_jinni/main.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; @@ -95,7 +94,7 @@ Future zonedScheduleNotification() async { ), ), ), - androidAllowWhileIdle: true, + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, ); @@ -136,18 +135,18 @@ Future showSoundUriNotification() async { /// this calls a method over a platform channel implemented within the /// example app to return the Uri for the default alarm sound and uses /// as the notification sound - final String? alarmUri = await platform.invokeMethod('getAlarmUri'); - final UriAndroidNotificationSound uriSound = - UriAndroidNotificationSound(alarmUri!); - final AndroidNotificationDetails androidPlatformChannelSpecifics = - AndroidNotificationDetails( - 'uri channel id', - 'uri channel name', - sound: uriSound, - styleInformation: const DefaultStyleInformation(true, true), - ); - final NotificationDetails platformChannelSpecifics = - NotificationDetails(android: androidPlatformChannelSpecifics); - await flutterLocalNotificationsPlugin! - .show(0, 'uri sound title', 'uri sound body', platformChannelSpecifics); + // final String? alarmUri = await platform.invokeMethod('getAlarmUri'); + // final UriAndroidNotificationSound uriSound = + // UriAndroidNotificationSound(alarmUri!); + // final AndroidNotificationDetails androidPlatformChannelSpecifics = + // AndroidNotificationDetails( + // 'uri channel id', + // 'uri channel name', + // sound: uriSound, + // styleInformation: const DefaultStyleInformation(true, true), + // ); + // final NotificationDetails platformChannelSpecifics = + // NotificationDetails(android: androidPlatformChannelSpecifics); + // await flutterLocalNotificationsPlugin! + // .show(0, 'uri sound title', 'uri sound body', platformChannelSpecifics); } diff --git a/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart b/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart index 731f48e1d..002185abd 100644 --- a/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart @@ -1,6 +1,6 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; import 'package:cbj_integrations_controller/domain/routine/value_objects_routine_cbj.dart'; +import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; diff --git a/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart b/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart index 2866d3d53..1984a1868 100644 --- a/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart +++ b/lib/presentation/pages/add_new_devices/add_new_cbj_devices.dart @@ -77,7 +77,6 @@ class _AddNewCBJDevices extends State { TopNavigationBar( pageName: 'Add New CyBear Jinni Devices', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), 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 c34a51018..98eaa2489 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 @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/vendors/vendors_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -45,11 +42,7 @@ class ChooseDeviceVendorToAddPage extends StatelessWidget { ), ), Expanded( - child: BlocProvider( - create: (context) => - getIt()..add(const VendorsEvent.initialized()), - child: VendorsList(), - ), + child: VendorsList(), ), const SizedBox( height: 50, 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 2787a4789..082d8f3b9 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 @@ -24,21 +24,9 @@ class VendorWidget extends StatelessWidget { if (vendorName == VendorsAndServices.lifx.name.toLowerCase()) { context.router.push(AddLifxVendorRoute(vendor: vendor)); - } else if (vendorName == - VendorsAndServices.tuyaSmart.name.toLowerCase()) { - context.router.push(AddTuyaVendorRoute(vendor: vendor)); - } else if (vendorName == - VendorsAndServices.smartLife.name.toLowerCase()) { - context.router.push(AddSmartLifeVendorRoute(vendor: vendor)); - } else if (vendorName == - VendorsAndServices.jinvooSmart.name.toLowerCase()) { - context.router.push(AddJinvooSmartVendorRoute(vendor: vendor)); } else if (vendorName == VendorsAndServices.espHome.name.toLowerCase()) { context.router.push(AddEspHomeVendorRoute(vendor: vendor)); - } else if (vendorName == - VendorsAndServices.xiaomiMi.name.toLowerCase()) { - context.router.push(AddXiaomiMiVendorRoute(vendor: vendor)); } else if (vendorName == VendorsAndServices.sonoffEweLink.name.toLowerCase()) { context.router.push(AddEwelinkVendorRoute(vendor: vendor)); diff --git a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart index 90f92e1dc..d094a2252 100644 --- a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart +++ b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart @@ -1,40 +1,49 @@ -import 'package:cybear_jinni/application/vendors/vendors_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:kt_dart/kt.dart'; + +class VendorsList extends StatefulWidget { + @override + State createState() => _VendorsListState(); +} + +class _VendorsListState extends State { + KtList vendorsList = [].toImmutableList(); + + @override + void initState() { + super.initState(); + initializeVendors(); + } + + Future initializeVendors() async { + final KtList temp = + (await IVendorsRepository.instance.getVendors()).fold( + (f) => [].toImmutableList(), + (vendorsListSuccess) => vendorsListSuccess, + ); + setState(() { + vendorsList = temp; + }); + } -class VendorsList extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - (value) => const TextAtom('sd'), - loading: (_) => const Center( - child: CircularProgressIndicator(), - ), - loaded: (state) { - return ListView.separated( - separatorBuilder: (_, __) => const SizedBox( - height: 16, - ), - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final vendor = state.vendorsList[index]; - return VendorWidget( - vendor, - ); - }, - itemCount: state.vendorsList.size, - ); - }, - error: (_) { - return const TextAtom('Error'); - }, + return ListView.separated( + separatorBuilder: (_, __) => const SizedBox( + height: 16, + ), + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final vendor = vendorsList[index]; + return VendorWidget( + vendor, ); }, + itemCount: vendorsList.size, ); } } diff --git a/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart b/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart index e424540ab..ffe9e513c 100644 --- a/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart +++ b/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart @@ -36,7 +36,6 @@ class ComputerConnectionCheckPage extends StatelessWidget { TopNavigationBar( pageName: 'Final setting up step', rightIcon: null, - rightIconFunction: null, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: leftIconFunction, ), diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart index 5362f587d..018eb1d78 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart @@ -36,7 +36,6 @@ class ConfigureNewCbjCompPage extends StatelessWidget { TopNavigationBar( pageName: 'Add CBJ Computer', rightIcon: null, - rightIconFunction: null, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: leftIconFunction, ), diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index 0009a9042..84925c4a7 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -249,7 +249,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { ), ), // child: Center( - // child: CircularProgressIndicator( + // child: CircularProgressIndicatorAtom( // backgroundColor: Colors.cyan, // strokeWidth: 5, // ), diff --git a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart index d9aeae481..6674c2b51 100644 --- a/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart @@ -41,7 +41,6 @@ class ConnectToHomeWifiPage extends StatelessWidget { TopNavigationBar( pageName: 'Add Devices', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart index 2dd2e7540..22ee28f6a 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart @@ -44,7 +44,6 @@ class OpenAccessPointPage extends StatelessWidget { TopNavigationBar( pageName: 'Add Devices', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart index 3459be8aa..d7aaf2cf4 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart @@ -32,10 +32,7 @@ class OpenAccessPointWidget extends StatelessWidget { ); }, loading: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); + return const CircularProgressIndicatorAtom(); }, loaded: (l) { // ExtendedNavigator.of(context) diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart index 70d980aab..9b2a7a8bb 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart @@ -33,7 +33,6 @@ class ScanForNewCBJCompsPage extends StatelessWidget { TopNavigationBar( pageName: 'Add CBJ Devices', rightIcon: null, - rightIconFunction: null, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: leftIconFunction, ), diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart index e1d803ea4..b6ed48e38 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart @@ -31,7 +31,7 @@ class ScanForNewCBJCompsWidget extends StatelessWidget { ), const Expanded( child: Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), ), ], @@ -48,7 +48,7 @@ class ScanForNewCBJCompsWidget extends StatelessWidget { return const Expanded( child: Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), ); }, diff --git a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart b/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart index 1a5c741a1..1ef567f24 100644 --- a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart +++ b/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart @@ -15,14 +15,13 @@ class AddUserToHomeWidget extends StatelessWidget { state.map( (value) => const TextAtom('Initial'), actionInProgress: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); + return const CircularProgressIndicatorAtom(); }, addingUserSuccess: (s) { return TextButton( - onPressed: () {}, child: const TextAtom('Success')); + onPressed: () {}, + child: const TextAtom('Success'), + ); }, addingHomeFailure: (e) { return const TextAtom('Failure'); @@ -94,10 +93,7 @@ class AddUserToHomeWidget extends StatelessWidget { state.map( (value) => const SizedBox(), actionInProgress: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); + return const CircularProgressIndicatorAtom(); }, addingUserSuccess: (s) { return Container( diff --git a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart index aff374e71..25eea27bb 100644 --- a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/add_esphome_vendor_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() class AddEspHomeVendorPage extends StatelessWidget { @@ -20,10 +17,7 @@ class AddEspHomeVendorPage extends StatelessWidget { backgroundColor: Colors.black, title: const TextAtom('EspHome Sign In'), ), - body: BlocProvider( - create: (context) => getIt(), - child: EspHomeSignInForm(vendor), - ), + body: EspHomeSignInForm(vendor), ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart index 047060788..a908395ac 100644 --- a/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_esphome_vendor/widgets/esphome_sign_in_form.dart @@ -1,143 +1,112 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/esphome_login/generic_esphome_login_entity.dart'; +import 'package:cbj_integrations_controller/domain/vendors/esphome_login/generic_esphome_login_value_objects.dart'; +import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/esphome_auth/esphome_sign_in_form/esphome_sign_in_form_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class EspHomeSignInForm extends StatelessWidget { +class EspHomeSignInForm extends StatefulWidget { const EspHomeSignInForm(this.vendor); final VendorData vendor; + @override + State createState() => _EspHomeSignInFormState(); +} + +class _EspHomeSignInFormState extends State { + String? password; + + void _login() { + if (password == null) { + return; + } + + Navigator.pop(context); + + IVendorsRepository.instance.loginWithEspHome( + GenericEspHomeLoginDE( + espHomeDevicePass: GenericEspHomeDeviceLoginApiPass(password), + senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), + ), + ); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const EspHomeSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - vendor.image ?? '', - ), - fit: BoxFit.fitHeight, - ), + return Form( + autovalidateMode: AutovalidateMode.onUserInteraction, + child: ListView( + padding: const EdgeInsets.all(8), + children: [ + Hero( + tag: 'Logo', + child: CircleAvatar( + backgroundColor: Colors.transparent, + radius: screenSize.height * 0.1, + child: Container( + width: 180, + height: 180, + decoration: BoxDecoration( + image: DecorationImage( + image: NetworkImage( + widget.vendor.image ?? '', ), + fit: BoxFit.fitHeight, ), - // ImageAtom('assets/cbj_logo.png'), ), ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.key, - ), - labelText: 'ESPHome device password', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(EspHomeSignInFormEvent.apiKeyChanged(value)), - validator: (_) => context - .read() - .state - .espHomeDevicePassword - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, + // ImageAtom('assets/cbj_logo.png'), + ), + ), + const SizedBox( + height: 8, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon( + FontAwesomeIcons.key, ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const EspHomeSignInFormEvent - .signInWithEspHomeApiKey(), - ); + labelText: 'ESPHome device password', + ), + autocorrect: false, + onChanged: (value) { + password = value; + }, + ), + const SizedBox( + height: 8, + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + _login(); - Fluttertoast.showToast( - msg: 'Sign in to ESPHome, devices will appear in the ' - 'app after getting discovered', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.deepPurple, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, + Fluttertoast.showToast( + msg: 'Sign in to ESPHome, devices will appear in the ' + 'app after getting discovered', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.deepPurple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + Navigator.pop(context); + }, + child: const TextAtom('SIGN IN'), ), - const LinearProgressIndicator(), - ], + ), ], ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart index 719fdbb22..e694ad7f2 100644 --- a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/add_ewelink_vendor_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() class AddEwelinkVendorPage extends StatelessWidget { @@ -20,10 +17,7 @@ class AddEwelinkVendorPage extends StatelessWidget { backgroundColor: Colors.blueAccent, title: const TextAtom('eWeLink Sign In'), ), - body: BlocProvider( - create: (context) => getIt(), - child: EwelinkSignInForm(vendor), - ), + body: EwelinkSignInForm(vendor), ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart index fbb5b5132..42bb56d46 100644 --- a/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_ewelink_vendor/widgets/ewelink_sign_in_form.dart @@ -1,173 +1,138 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/ewelink_login/generic_ewelink_login_entity.dart'; +import 'package:cbj_integrations_controller/domain/vendors/ewelink_login/generic_ewelink_login_value_objects.dart'; +import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/ewelink_auth/ewelink_sign_in_form/ewelink_sign_in_form_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class EwelinkSignInForm extends StatelessWidget { +class EwelinkSignInForm extends StatefulWidget { const EwelinkSignInForm(this.vendor); final VendorData vendor; + @override + State createState() => _EwelinkSignInFormState(); +} + +class _EwelinkSignInFormState extends State { + String? email; + String? password; + + Future _signInWithEwelink() async { + if (email == null || password == null) { + Fluttertoast.showToast( + msg: 'Please enter Email and Password', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.deepPurple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + return; + } + + Fluttertoast.showToast( + msg: 'Sign in to eWeLink, devices will appear in the ' + 'app after getting discovered', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.deepPurple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + Navigator.pop(context); + + final GenericEwelinkLoginDE genericEwelinkDE = GenericEwelinkLoginDE( + senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), + ewelinkAccountEmail: GenericEwelinkAccountEmail(email), + ewelinkAccountPass: GenericEwelinkAccountPass(password), + ); + IVendorsRepository.instance.loginWithEwelink(genericEwelinkDE); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const EwelinkSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage(vendor.image ?? ''), - fit: BoxFit.fitHeight, - ), - ), + return Form( + autovalidateMode: AutovalidateMode.onUserInteraction, + child: ListView( + padding: const EdgeInsets.all(8), + children: [ + Hero( + tag: 'Logo', + child: CircleAvatar( + backgroundColor: Colors.transparent, + radius: screenSize.height * 0.1, + child: Container( + width: 180, + height: 180, + decoration: BoxDecoration( + image: DecorationImage( + image: NetworkImage(widget.vendor.image ?? ''), + fit: BoxFit.fitHeight, ), - // ImageAtom('assets/cbj_logo.png'), ), ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.at, - ), - labelText: 'eWeLink device email', - ), - autocorrect: false, - onChanged: (value) => context.read().add( - EwelinkSignInFormEvent.ewelinkAccountEmailChange( - value, - ), - ), - validator: (_) => context - .read() - .state - .ewelinkAccountEmail - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), + // ImageAtom('assets/cbj_logo.png'), + ), + ), + const SizedBox( + height: 8, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon( + FontAwesomeIcons.at, ), - const SizedBox( - height: 8, + labelText: 'eWeLink device email', + ), + autocorrect: false, + onChanged: (value) { + email = value; + }, + validator: (_) { + return null; + }, + ), + const SizedBox( + height: 8, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon( + FontAwesomeIcons.key, ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.key, - ), - labelText: 'eWeLink device password', + labelText: 'eWeLink device password', + ), + autocorrect: false, + onChanged: (value) { + password = value; + }, + validator: (_) { + return null; + }, + ), + const SizedBox( + height: 8, + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + _signInWithEwelink(); + }, + child: const TextAtom('SIGN IN'), ), - autocorrect: false, - onChanged: (value) => context.read().add( - EwelinkSignInFormEvent.ewelinkAccountPassChange( - value, - ), - ), - validator: (_) => context - .read() - .state - .ewelinkAccountPass - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const EwelinkSignInFormEvent.signInWithEwelink(), - ); - - Fluttertoast.showToast( - msg: 'Sign in to eWeLink, devices will appear in the ' - 'app after getting discovered', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.deepPurple, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], ], ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart deleted file mode 100644 index c77ffd01a..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/add_jinvoo_smart_vendor_page.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class AddJinvooSmartVendorPage extends StatelessWidget { - const AddJinvooSmartVendorPage(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.indigo, - title: const TextAtom('Jinvoo Smart Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: JinvooSmartSignInForm(vendor), - ), - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart deleted file mode 100644 index 9c55c458c..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_jinvoo_smart_vendor/widgets/jinvoo_smart_sign_in_form.dart +++ /dev/null @@ -1,243 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class JinvooSmartSignInForm extends StatelessWidget { - const JinvooSmartSignInForm(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - IconData; - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const TuyaSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Column( - children: [ - Expanded( - child: Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - vendor.image ?? '', - ), - fit: BoxFit.fitHeight, - ), - ), - ), - // ImageAtom('assets/cbj_logo.png'), - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.rightToBracket), - labelText: 'Jinvoo Smart User Name', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userNameChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserName - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - obscureText: true, - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.unlock), - labelText: 'Jinvoo Smart User Password', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userPasswordChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserPassword - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.flag), - labelText: 'Jinvoo Smart Country Code', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.countryCodeChanged(value)), - validator: (_) => context - .read() - .state - .tuyaCountryCode - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - const TextAtom( - 'Select Region:', - style: TextStyle(color: Colors.black), - ), - DropdownButton( - value: context - .read() - .state - .tuyaLoginRegion - .getOrCrash(), - icon: const Icon(Icons.arrow_drop_down), - hint: const TextAtom('Jinvoo Smart Region'), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.regionChanged(value)), - items: [ - 'us', - 'eu', - 'cn', - ].map>((String value) { - return DropdownMenuItem( - value: value, - child: TextAtom(value), - ); - }).toList(), - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - TuyaSignInFormEvent.vendorChanged( - VendorsAndServices.jinvooSmart.name, - ), - ); - context.read().add( - const TuyaSignInFormEvent - .signInWithTuyaApiKey(), - ); - - Fluttertoast.showToast( - msg: - 'Sign in to Jinvoo Smart, devices will appear in the shortly', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.indigo, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], - ], - ), - ), - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart index 50a464125..cbec927f6 100644 --- a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart +++ b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/add_lifx_vendor_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() class AddLifxVendorPage extends StatelessWidget { @@ -18,12 +15,9 @@ class AddLifxVendorPage extends StatelessWidget { return Scaffold( appBar: AppBar( backgroundColor: Colors.deepPurple, - title: const TextAtom('Xiaomi Mi Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: LifxSignInForm(vendor), + title: const TextAtom('Lifx Sign In'), ), + body: LifxSignInForm(vendor), ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart index 8ee390511..44777b569 100644 --- a/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart +++ b/lib/presentation/pages/add_vendors_pages/add_lifx_vendor/widgets/lifx_sign_in_form.dart @@ -1,169 +1,127 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; +import 'package:cbj_integrations_controller/domain/vendors/i_vendor_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/lifx_login/generic_lifx_login_entity.dart'; +import 'package:cbj_integrations_controller/domain/vendors/lifx_login/generic_lifx_login_value_objects.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/value_login_objects_core.dart'; import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/lifx_auth/lifx_sign_in_form/lifx_sign_in_form_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:url_launcher/url_launcher.dart'; -class LifxSignInForm extends StatelessWidget { +class LifxSignInForm extends StatefulWidget { const LifxSignInForm(this.vendor); final VendorData vendor; + @override + State createState() => _LifxSignInFormState(); +} + +class _LifxSignInFormState extends State { + String? api; + + Future _signInWithApiKey() async { + Fluttertoast.showToast( + msg: 'Sign in to Lifx, devices will appear in the shortly', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.deepPurple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + final GenericLifxLoginDE genericLifxDE = GenericLifxLoginDE( + senderUniqueId: CoreLoginSenderId.fromUniqueString('Me'), + lifxApiKey: GenericLifxLoginApiKey(api), + ); + IVendorsRepository.instance.loginWithLifx(genericLifxDE); + Navigator.pop(context); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const LifxSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Column( - children: [ - Expanded( - child: Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - vendor.image ?? '', - ), - fit: BoxFit.fitHeight, - ), + return Column( + children: [ + Expanded( + child: Form( + autovalidateMode: AutovalidateMode.onUserInteraction, + child: ListView( + padding: const EdgeInsets.all(8), + children: [ + Hero( + tag: 'Logo', + child: CircleAvatar( + backgroundColor: Colors.transparent, + radius: screenSize.height * 0.1, + child: Container( + width: 180, + height: 180, + decoration: BoxDecoration( + image: DecorationImage( + image: NetworkImage( + widget.vendor.image ?? '', ), + fit: BoxFit.fitHeight, ), - // ImageAtom('assets/cbj_logo.png'), ), ), - const SizedBox( - height: 8, + // ImageAtom('assets/cbj_logo.png'), + ), + ), + const SizedBox( + height: 8, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon( + FontAwesomeIcons.key, ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.key, - ), - labelText: 'Lifx API Key', + labelText: 'Lifx API Key', + ), + autocorrect: false, + onChanged: (value) { + api = value; + }, + ), + const SizedBox( + height: 8, + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + _signInWithApiKey(); + }, + child: const TextAtom('SIGN IN'), ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(LifxSignInFormEvent.apiKeyChanged(value)), - validator: (_) => context - .read() - .state - .lifxApiKey - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const LifxSignInFormEvent - .signInWithLifxApiKey(), - ); - - Fluttertoast.showToast( - msg: - 'Sign in to Lifx, devices will appear in the shortly', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.deepPurple, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], ], ), - ), + ], ), - Container( - alignment: Alignment.bottomRight, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.pink), - ), - onPressed: () { - launchUrl(Uri.parse('https://cloud.lifx.com/')); - }, - child: TextAtom( - 'Get Lifx API key from Lifx website', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), + ), + ), + Container( + alignment: Alignment.bottomRight, + child: TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(Colors.pink), + ), + onPressed: () { + launchUrl(Uri.parse('https://cloud.lifx.com/')); + }, + child: TextAtom( + 'Get Lifx API key from Lifx website', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - ], - ); - }, + ), + ), + ], ); } } diff --git a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart deleted file mode 100644 index 0d4be6081..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/add_smart_life_vendor_page.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class AddSmartLifeVendorPage extends StatelessWidget { - const AddSmartLifeVendorPage(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.lightBlueAccent, - title: const TextAtom('Smart Life Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: SmartLifeSignInForm(vendor), - ), - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart deleted file mode 100644 index bac2799d9..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_smart_life_vendor/widgets/smart_life_sign_in_form.dart +++ /dev/null @@ -1,244 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class SmartLifeSignInForm extends StatelessWidget { - const SmartLifeSignInForm(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const TuyaSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Column( - children: [ - Expanded( - child: Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - vendor.image ?? '', - ), - fit: BoxFit.fitHeight, - ), - ), - ), - // ImageAtom('assets/cbj_logo.png'), - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.rightToBracket), - labelText: 'Smart Life User Name', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userNameChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserName - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - obscureText: true, - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.unlock), - labelText: 'Smart Life User Password', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userPasswordChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserPassword - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.flag), - labelText: 'Smart Life Country Code', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.countryCodeChanged(value)), - validator: (_) => context - .read() - .state - .tuyaCountryCode - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - const TextAtom( - 'Select Region:', - style: TextStyle(color: Colors.black), - ), - DropdownButton( - value: context - .read() - .state - .tuyaLoginRegion - .getOrCrash(), - icon: const Icon(Icons.arrow_drop_down), - hint: const TextAtom('Smart Life Region'), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.regionChanged(value)), - items: [ - 'us', - 'eu', - 'cn', - ].map>((String value) { - return DropdownMenuItem( - value: value, - child: TextAtom(value), - ); - }).toList(), - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - TuyaSignInFormEvent.vendorChanged( - VendorsAndServices.smartLife.name, - ), - ); - context.read().add( - const TuyaSignInFormEvent - .signInWithTuyaApiKey(), - ); - - Fluttertoast.showToast( - msg: - 'Sign in to Smart Life, please restart the ' - 'app to see the new devices', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.lightBlueAccent, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], - ], - ), - ), - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart deleted file mode 100644 index df3dec964..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/add_tuya_vendor_page.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class AddTuyaVendorPage extends StatelessWidget { - const AddTuyaVendorPage(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.deepOrange, - title: const TextAtom('Tuya Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: TuyaSignInForm(vendor), - ), - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart deleted file mode 100644 index b1158e8c7..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_tuya_vendor/widgets/tuya_sign_in_form.dart +++ /dev/null @@ -1,243 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/tuya_auth/tuya_sign_in_form/tuya_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class TuyaSignInForm extends StatelessWidget { - const TuyaSignInForm(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const TuyaSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Column( - children: [ - Expanded( - child: Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage( - vendor.image ?? '', - ), - fit: BoxFit.fitHeight, - ), - ), - ), - // ImageAtom('assets/cbj_logo.png'), - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.rightToBracket), - labelText: 'Tuya User Name', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userNameChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserName - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - obscureText: true, - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.unlock), - labelText: 'Tuya User Password', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.userPasswordChanged(value)), - validator: (_) => context - .read() - .state - .tuyaUserPassword - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.flag), - labelText: 'Tuya Country Code', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.countryCodeChanged(value)), - validator: (_) => context - .read() - .state - .tuyaCountryCode - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - const TextAtom( - 'Select Region:', - style: TextStyle(color: Colors.black), - ), - DropdownButton( - value: context - .read() - .state - .tuyaLoginRegion - .getOrCrash(), - icon: const Icon(Icons.arrow_drop_down), - hint: const TextAtom('Tuna Region'), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) => context - .read() - .add(TuyaSignInFormEvent.regionChanged(value)), - items: [ - 'us', - 'eu', - 'cn', - ].map>((String value) { - return DropdownMenuItem( - value: value, - child: TextAtom(value), - ); - }).toList(), - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - TuyaSignInFormEvent.vendorChanged( - VendorsAndServices.tuyaSmart.name, - ), - ); - context.read().add( - const TuyaSignInFormEvent - .signInWithTuyaApiKey(), - ); - - Fluttertoast.showToast( - msg: - 'Sign in to Tuya, devices will appear in the shortly', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.deepOrange, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], - ], - ), - ), - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart deleted file mode 100644 index 782f8f074..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/add_xiaomi_mi_vendor_page.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class AddXiaomiMiVendorPage extends StatelessWidget { - const AddXiaomiMiVendorPage(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.deepOrange, - title: const TextAtom('XiaomiMi Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: XiaomiMiSignInForm(vendor), - ), - ); - } -} diff --git a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart b/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart deleted file mode 100644 index 9fa1b2aaf..000000000 --- a/lib/presentation/pages/add_vendors_pages/add_xiaomi_mi_vendor/widgets/xiaomi_mi_sign_in_form.dart +++ /dev/null @@ -1,175 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/domain/vendors/vendor_data.dart'; -import 'package:cybear_jinni/application/xiaomi_mi_auth/xiaomi_mi_sign_in_form/xiaomi_mi_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class XiaomiMiSignInForm extends StatelessWidget { - const XiaomiMiSignInForm(this.vendor); - - final VendorData vendor; - - @override - Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (Either either) => either.fold( - (CoreLoginFailure failure) => { - FlushbarHelper.createError( - message: 'Validation error', - // failure.map( - // cancelledByUser: (_) => 'Cancelled', - // serverError: (_) => 'Server error', - // invalidApiKey: (_) => 'Email already in use', - // ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - // context - // .read()() - // .add(const XiaomiMiSignInFormEvent.()); - }), - ); - }, - builder: (context, state) { - return Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'Logo', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: Container( - width: 180, - height: 180, - decoration: BoxDecoration( - image: DecorationImage( - image: NetworkImage(vendor.image ?? ''), - fit: BoxFit.fitHeight, - ), - ), - ), - // ImageAtom('assets/cbj_logo.png'), - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.at, - ), - labelText: 'Xiaomi Mi device email', - ), - autocorrect: false, - onChanged: (value) => - context.read().add( - XiaomiMiSignInFormEvent.xiaomiMiAccountEmailChange( - value, - ), - ), - validator: (_) => context - .read() - .state - .xiaomiMiAccountEmail - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon( - FontAwesomeIcons.key, - ), - labelText: 'Xiaomi Mi device password', - ), - autocorrect: false, - onChanged: (value) => - context.read().add( - XiaomiMiSignInFormEvent.xiaomiMiAccountPassChange( - value, - ), - ), - validator: (_) => context - .read() - .state - .xiaomiMiAccountPass - .value - .fold( - (CoreLoginFailure f) => 'Validation error', - // f.maybeMap( - // invalidEmail: (result) => result.failedValue, - // containsSpace: (result) => result.failedValue, - // orElse: () => null, - // ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const XiaomiMiSignInFormEvent.signInWithXiaoMi(), - ); - - Fluttertoast.showToast( - msg: - 'Sign in to Xiaomi Mi, devices will appear in the ' - 'app after getting discovered', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.deepPurple, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('SIGN IN'), ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], - ], - ), - ); - }, - ); - } -} diff --git a/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart b/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart index b21df1023..18c71f584 100644 --- a/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart +++ b/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart @@ -29,7 +29,6 @@ class ChangeRoomForDevicesPage extends StatelessWidget { TopNavigationBar( pageName: 'Change Area For Devices', rightIcon: null, - rightIconFunction: null, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart index 24efac0c2..72c9d22bc 100644 --- a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart +++ b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart @@ -1,6 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/domain/hub/hub_failures.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; +import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart' as dartz; @@ -41,9 +43,16 @@ class _CbjHubInNetworkWidgetState extends State { eitherHub.fold((l) async { await IHubConnectionRepository.instance.closeConnection(); + final Map devices = + await PhoneHub().getAllDevices; + if (!mounted) { return null; } + if (devices.isNotEmpty) { + context.router.replace(const HomeRoute()); + return; + } setState(() { state = FindingHubState.tryIpManually; }); @@ -76,7 +85,7 @@ class _CbjHubInNetworkWidgetState extends State { return const SizedBox( height: 70, width: 70, - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ); } @@ -128,7 +137,8 @@ class _CbjHubInNetworkWidgetState extends State { return; } _searchHubUsingAnyIpOnTheNetwork( - ipOnTheNetwork: anyIpOnTheNetwork); + ipOnTheNetwork: anyIpOnTheNetwork, + ); }, child: const TextAtom( 'Search', diff --git a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart index 1acb3a58f..ac62c4d60 100644 --- a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart +++ b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart @@ -139,7 +139,7 @@ class ConnectToHubMoreWidget extends StatelessWidget { loadInProgress: (_) => const SizedBox( height: 70, width: 70, - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (_) => const TextAtom('Found hub'), loadFailure: (failure) => const TextAtom('Failure'), diff --git a/lib/presentation/pages/create_home/widgets/create_home_widget.dart b/lib/presentation/pages/create_home/widgets/create_home_widget.dart index 692ee90da..fdda9a20a 100644 --- a/lib/presentation/pages/create_home/widgets/create_home_widget.dart +++ b/lib/presentation/pages/create_home/widgets/create_home_widget.dart @@ -124,7 +124,7 @@ class CreateHomeWidget extends StatelessWidget { return const TextAtom(''); }, loading: (loadingNow) { - return const CircularProgressIndicator(); + return const CircularProgressIndicatorAtom(); }, error: (errorNow) { FlushbarHelper.createError(message: 'Error'); diff --git a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart index 6b2253c1b..023aca769 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_page.dart @@ -36,11 +36,9 @@ class BlindsInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart index b8186885a..090a11257 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/blinds_in_the_room/blinds_in_the_room_widget.dart @@ -13,7 +13,7 @@ class BlindsInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart b/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart index b3acf5582..8d9cab71d 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart @@ -96,7 +96,6 @@ class SettingsPageOfBlinds extends StatelessWidget { TopNavigationBar( pageName: 'Lights Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart index 6ff91e2b0..f295c1a43 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/smart_blind_widget.dart @@ -89,7 +89,7 @@ class _SmartBlindPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else FlutterSwitch( width: screenSize.width * 0.25, diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart index 34217252c..3344a59cc 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/blinds/blinds_watcher/blinds_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart'; import 'package:flutter/material.dart'; @@ -25,7 +24,7 @@ class RoomsBlindsWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -59,22 +58,14 @@ class RoomsBlindsWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - List? gradiantColor; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; + final KtList devicesInRoom = devicesByRooms[index]; @@ -97,7 +88,7 @@ class RoomsBlindsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart index 31e3c4ff2..68af5df17 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_page.dart @@ -36,11 +36,9 @@ class BoilersInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart index 2e35de364..a3b1421de 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/boilers_in_the_room/boilers_in_the_room_widget.dart @@ -13,7 +13,7 @@ class BoilersInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart index f6d5b15bd..51a506137 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart @@ -96,7 +96,6 @@ class SettingsPageOfBoilers extends StatelessWidget { TopNavigationBar( pageName: 'Lights Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart index 8271acfe6..1e94dd3f7 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/smart_boiler_widget.dart @@ -89,7 +89,7 @@ class _SmartBoilerPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else FlutterSwitch( width: screenSize.width * 0.25, diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart index 1aa1cf05b..a06400b6e 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart @@ -25,7 +25,7 @@ class RoomBoilers extends StatelessWidget { final int? maxBoilersToShow; - final int _maxBoilersInRow = 2; + int get _maxBoilersInRow => 2; final String? _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart index c44e0b12b..334e31c50 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart'; import 'package:flutter/material.dart'; @@ -25,7 +24,7 @@ class RoomsBoilersWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -59,23 +58,14 @@ class RoomsBoilersWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; return RoomBoilers( @@ -97,7 +87,7 @@ class RoomsBoilersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart index c4d134a44..65d1e7247 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_page.dart @@ -38,11 +38,9 @@ class LightsInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart index fe6a867d1..14884f8cc 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/lights_in_the_room/lights_in_the_room_widget.dart @@ -13,7 +13,7 @@ class LightsInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart b/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart index 0ece1e50e..1f88b0b11 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart @@ -96,7 +96,6 @@ class SettingsPageOfLights extends StatelessWidget { TopNavigationBar( pageName: 'Lights Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart index 899d7d6bf..2d43573be 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/smart_lighte_widget.dart @@ -89,7 +89,7 @@ class _SmartLightPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else FlutterSwitch( width: screenSize.width * 0.25, diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart index 5b28a9ffb..36718a70f 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart @@ -1,6 +1,6 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart index b42e5faa6..2090cde47 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart @@ -31,7 +31,7 @@ class RoomLights extends StatelessWidget { final int maxLightsToShow; - final int _maxLightsInRow = 2; + int get _maxLightsInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart index 3134c92b4..7a19d2af3 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart'; @@ -29,7 +28,7 @@ class RoomsLightsWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -63,22 +62,14 @@ class RoomsLightsWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant.listOfColors!; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = + roomColorGradiant.listOfColors!; + final devicesInRoom = devicesByRooms[index]; return RoomLights( @@ -100,7 +91,7 @@ class RoomsLightsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart index b22ad2543..5d7a2ea53 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printer_widget.dart @@ -18,7 +18,7 @@ class PrinterPage extends StatefulWidget { } class _SmartPrinterPage extends State { - GenericPrinterDE? _switch; + late GenericPrinterDE _switch; bool _isLoading = true; @override @@ -72,7 +72,7 @@ class _SmartPrinterPage extends State { return Column( children: [ TextAtom( - _switch!.cbjEntityName.getOrCrash()!, // Show switch name + _switch.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, color: Theme.of(context).textTheme.bodyMedium!.color, @@ -82,7 +82,7 @@ class _SmartPrinterPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else const TextAtom('Smart Computer Widget'), ], diff --git a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart index 0ee5b0314..2d3decddc 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_page.dart @@ -36,11 +36,9 @@ class PrintersInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart index 234d1135f..6b208551b 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/printers_in_the_room/printers_in_the_room_widget.dart @@ -14,7 +14,7 @@ class PrintersInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart b/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart index 85a2635a2..dd338c8c3 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart @@ -97,7 +97,6 @@ class SettingsPageOfPrinters extends StatelessWidget { TopNavigationBar( pageName: 'Printers Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart index 218194184..e5f983990 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart @@ -13,7 +13,7 @@ class PrinterWidget extends StatelessWidget { final GenericPrinterDE? _deviceEntity; void openPrintersWebPage(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + _deviceEntity!.getDeviceId(); context.read().add( PrintersActorEvent.openPrintersWebPage( _deviceEntity!, @@ -34,8 +34,6 @@ class PrinterWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( listener: (context, state) {}, builder: (context, state) { @@ -72,7 +70,8 @@ class PrinterWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ), ), + ), + ), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart index 6a748bae1..f2aa40056 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart @@ -25,7 +25,7 @@ class RoomPrinters extends StatelessWidget { final int maxPrintersToShow; - final int _maxPrintersInRow = 2; + int get _maxPrintersInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart index e90b2d97f..437560cfa 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; import 'package:cybear_jinni/utils.dart'; @@ -30,7 +29,7 @@ class RoomsPrintersWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -63,23 +62,13 @@ class RoomsPrintersWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; final devicesInRoom = devicesByRooms[index]; return RoomPrinters( @@ -101,7 +90,7 @@ class RoomsPrintersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart index c7d3a5afe..b65843dbc 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart @@ -97,7 +97,6 @@ class SettingsPageOfSmartComputers extends StatelessWidget { TopNavigationBar( pageName: 'SmartComputers Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart index d17c438c0..293d889e3 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computer_widget.dart @@ -18,7 +18,7 @@ class SmartComputerPage extends StatefulWidget { } class _SmartSmartComputerPage extends State { - GenericSmartComputerDE? _switch; + late GenericSmartComputerDE _switch; bool _isLoading = true; @override @@ -72,7 +72,7 @@ class _SmartSmartComputerPage extends State { return Column( children: [ TextAtom( - _switch!.cbjEntityName.getOrCrash()!, // Show switch name + _switch.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, color: Theme.of(context).textTheme.bodyMedium!.color, @@ -82,7 +82,7 @@ class _SmartSmartComputerPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else const TextAtom('Smart Computer Widget'), ], diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart index bfd5b1ef6..c32670d9f 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_page.dart @@ -36,11 +36,9 @@ class SmartComputersInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart index 349a36c82..9453a4c4c 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/smart_computers_in_the_room/smart_computers_in_the_room_widget.dart @@ -14,7 +14,7 @@ class SmartComputersInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart index 8889bd238..aab3e729d 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart @@ -25,7 +25,7 @@ class RoomSmartComputers extends StatelessWidget { final int maxSmartComputersToShow; - final int _maxSmartComputersInRow = 2; + int get _maxSmartComputersInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart index 418b8a814..40ecefc69 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart'; import 'package:cybear_jinni/utils.dart'; @@ -30,7 +29,7 @@ class RoomsSmartComputersWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -63,23 +62,14 @@ class RoomsSmartComputersWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; return RoomSmartComputers( @@ -101,7 +91,7 @@ class RoomsSmartComputersWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart index 879890888..0c7e49030 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart @@ -98,7 +98,6 @@ class SettingsPageOfSmartPlugs extends StatelessWidget { TopNavigationBar( pageName: 'SmartPlugs Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart index 677909210..07859bc2b 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plug_widget.dart @@ -89,7 +89,7 @@ class _SmartSmartPlugPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else FlutterSwitch( width: screenSize.width * 0.25, diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart index 9dc1b1ee4..3033fe29d 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_page.dart @@ -38,11 +38,9 @@ class SmartPlugsInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart index 5a9c2ec6c..d6580eef2 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/smart_plugs_in_the_room/smart_plugs_in_the_room_widget.dart @@ -14,7 +14,7 @@ class SmartPlugsInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart index 968783ee7..29f4fd282 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart @@ -25,7 +25,7 @@ class RoomSmartPlugs extends StatelessWidget { final int maxSmartPlugsToShow; - final int _maxSmartPlugsInRow = 2; + int get _maxSmartPlugsInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart index 6e6327262..a841d9663 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart'; import 'package:cybear_jinni/utils.dart'; @@ -30,7 +29,7 @@ class RoomsSmartPlugsWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -64,23 +63,13 @@ class RoomsSmartPlugsWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; final devicesInRoom = devicesByRooms[index]; return RoomSmartPlugs( @@ -102,7 +91,7 @@ class RoomsSmartPlugsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart index 753549da4..1d64bba85 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart @@ -30,16 +30,20 @@ class SettingsPageOfSmartTvs extends StatelessWidget { leading: CircleAvatar( child: Icon(MdiIcons.lightSwitch), ), - title: TextAtom('Name:_', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - translationArgs: [switchName]), - subtitle: TextAtom('Room:_', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - translationArgs: [roomName]), + title: TextAtom( + 'Name:_', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + translationArgs: [switchName], + ), + subtitle: TextAtom( + 'Room:_', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + translationArgs: [roomName], + ), trailing: IconButton( icon: FaIcon( FontAwesomeIcons.pen, @@ -93,7 +97,6 @@ class SettingsPageOfSmartTvs extends StatelessWidget { TopNavigationBar( pageName: 'SmartTvs Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart index e16b328ff..7605444b0 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tv_widget.dart @@ -18,7 +18,7 @@ class SmartTvPage extends StatefulWidget { } class _SmartSmartTvPage extends State { - GenericSmartTvDE? _switch; + late GenericSmartTvDE _switch; bool _isLoading = true; @override @@ -72,7 +72,7 @@ class _SmartSmartTvPage extends State { return Column( children: [ TextAtom( - _switch!.cbjEntityName.getOrCrash()!, // Show switch name + _switch.cbjEntityName.getOrCrash()!, // Show switch name style: TextStyle( fontSize: 19.0, color: Theme.of(context).textTheme.bodyMedium!.color, @@ -82,7 +82,7 @@ class _SmartSmartTvPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else const TextAtom('Smart Tv Widget'), ], diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart index 6438e3499..129f0540e 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_page.dart @@ -36,11 +36,9 @@ class SmartTvsInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart index e4522c515..51543e060 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/smart_tvs_in_the_room/smart_computers_in_the_room_widget.dart @@ -14,7 +14,7 @@ class SmartTvsInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart index 042e2e49c..b914d8319 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart @@ -10,9 +10,9 @@ class OpenUrlPopUp { } BuildContext contextFromParent; - final GenericSmartTvDE? _deviceEntity; + final GenericSmartTvDE _deviceEntity; - openUrlPopUp() { + void openUrlPopUp() { String url = ''; showDialog( @@ -83,7 +83,7 @@ class OpenUrlPopUp { } void playVideo(BuildContext context, String url) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.openUrl( context, diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart index 3cc89dac7..58bc1dd52 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart @@ -25,7 +25,7 @@ class RoomSmartTvs extends StatelessWidget { final int maxSmartTvsToShow; - final int _maxSmartTvsInRow = 2; + int get _maxSmartTvsInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart index 421bbe49e..5f9b8436b 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart'; import 'package:cybear_jinni/utils.dart'; @@ -30,7 +29,7 @@ class RoomsSmartTvsWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -63,23 +62,14 @@ class RoomsSmartTvsWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; return RoomSmartTvs( @@ -101,7 +91,7 @@ class RoomsSmartTvsWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart index 1bdf4d074..3e48bd8b1 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart @@ -11,10 +11,10 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class SmartTvWidget extends StatelessWidget { const SmartTvWidget(this._deviceEntity); - final GenericSmartTvDE? _deviceEntity; + final GenericSmartTvDE _deviceEntity; void stopState(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.stopEvent( [deviceId], @@ -33,7 +33,7 @@ class SmartTvWidget extends StatelessWidget { // ); // } void closeEvent(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.closeEvent( [deviceId], @@ -43,7 +43,7 @@ class SmartTvWidget extends StatelessWidget { } void playEvent(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.playEvent( [deviceId], @@ -53,7 +53,7 @@ class SmartTvWidget extends StatelessWidget { } void queueNextEvent(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.queueNextEvent( [deviceId], @@ -63,7 +63,7 @@ class SmartTvWidget extends StatelessWidget { } void queuePrevEvent(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); + final String deviceId = _deviceEntity.getDeviceId(); context.read().add( SmartTvActorEvent.queuePrevEvent( [deviceId], @@ -119,7 +119,8 @@ class SmartTvWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ), ), + ), + ), ), const SizedBox( width: 10, @@ -151,7 +152,8 @@ class SmartTvWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ), ), + ), + ), ), const SizedBox( width: 5, @@ -183,7 +185,8 @@ class SmartTvWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ), ), + ), + ), ), const SizedBox( width: 5, @@ -215,7 +218,8 @@ class SmartTvWidget extends StatelessWidget { color: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16, ), - ), ), + ), + ), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart b/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart index 930ee5a11..88bdeee3c 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart @@ -97,7 +97,6 @@ class SettingsPageOfSwitches extends StatelessWidget { TopNavigationBar( pageName: 'Switches Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart index cdaa38e00..6e070e15e 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/smart_switch_widget.dart @@ -89,7 +89,7 @@ class _SmartSwitchPage extends State { height: 3, ), if (_isLoading) - const Center(child: CircularProgressIndicator()) + const Center(child: CircularProgressIndicatorAtom()) else FlutterSwitch( width: screenSize.width * 0.25, diff --git a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart index bb9e2da37..2680c0d58 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_page.dart @@ -38,11 +38,9 @@ class SwitchesInTheRoomPage extends StatelessWidget { TopNavigationBar( pageName: thisSmartRoom!.getRoomName(), rightIcon: Icons.more_vert, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: () {}, ), Expanded( child: Container( diff --git a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart index ed8798dd7..028e15200 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/switches_in_the_room/switches_in_the_room_widget.dart @@ -14,7 +14,7 @@ class SwitchesInTheRoomWidget extends StatelessWidget { ); final Function updateProduct; - final Function deleteProduct; + final Function(int) deleteProduct; final List> products; @override diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart index 94423032d..fd27aa7cd 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart @@ -25,7 +25,7 @@ class RoomSwitches extends StatelessWidget { final int maxSwitchesToShow; - final int _maxSwitchesInRow = 2; + int get _maxSwitchesInRow => 2; final String _roomEntity; diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart index 347c7d86e..5ee752301 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart @@ -2,7 +2,6 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cybear_jinni/application/switches/switches_watcher/switches_watcher_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart'; import 'package:cybear_jinni/utils.dart'; @@ -30,7 +29,7 @@ class RoomsSwitchesWidget extends StatelessWidget { return state.map( initial: (_) => Container(), loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { if (state.devices.size != 0) { @@ -63,23 +62,14 @@ class RoomsSwitchesWidget extends StatelessWidget { devicesByRooms.add(v.toImmutableList()); }); - int gradientColorCounter = -1; - return Container( margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), child: ListView.builder( reverse: true, padding: EdgeInsets.zero, itemBuilder: (context, index) { - gradientColorCounter++; - List gradiantColor = GradientColors.sky; - if (roomColorGradiant != null) { - gradiantColor = roomColorGradiant; - } else if (gradientColorCounter > - gradientColorsList.length - 1) { - gradientColorCounter = 0; - gradiantColor = gradientColorsList[gradientColorCounter]; - } + final List gradiantColor = roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; return RoomSwitches( @@ -101,7 +91,7 @@ class RoomsSwitchesWidget extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart b/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart index e26f176aa..6d2864aee 100644 --- a/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart +++ b/lib/presentation/pages/home_page/bottom_navigation_bar_home_page.dart @@ -4,7 +4,7 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart class BottomNavigationBarHomePage extends StatelessWidget { const BottomNavigationBarHomePage(this.callback, this.pageIndex); - final Function callback; + final Function(int) callback; final int pageIndex; @@ -14,7 +14,7 @@ class BottomNavigationBarHomePage extends StatelessWidget { selectedItemColor: Theme.of(context).primaryColor, unselectedItemColor: Colors.grey[500], currentIndex: pageIndex, - onTap: (value) => callback(value), + onTap: callback, items: [ BottomNavigationBarItem( activeIcon: Icon(MdiIcons.sitemap), diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index eeb0bc9f7..1780dd4b8 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -2,7 +2,6 @@ import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/bottom_navigation_bar_home_page.dart'; -import 'package:cybear_jinni/presentation/pages/home_page/left_navigation_drawer_home_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart'; import 'package:cybear_jinni/presentation/pages/plus_button/plus_button.dart'; @@ -74,7 +73,6 @@ class _HomePageState extends State { controller: _pageController, children: _pages, ), - drawer: LeftNavigationDrawerHomePage(), bottomNavigationBar: BottomNavigationBarHomePage(callback, _currentTabNum), ), diff --git a/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart b/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart deleted file mode 100644 index ad5a4148e..000000000 --- a/lib/presentation/pages/home_page/left_navigation_drawer_home_page.dart +++ /dev/null @@ -1,192 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:cybear_jinni/utils.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class LeftNavigationDrawerHomePage extends StatelessWidget { - Future _fireBaseLogOut(BuildContext context) async { - try { - context.router.replace(const ConnectToHubRoute()); - } catch (e) { - logger.e(e); // TODO: show dialog with error - } - } - - @override - Widget build(BuildContext context) { - return Drawer( - // Add a ListView to the drawer. This ensures the user can scroll - // through the options in the drawer if there isn't enough vertical - // space to fit everything. - child: ColoredBox( - color: Colors.black54, - child: ListView( - reverse: true, - children: [ - ColoredBox( - color: Colors.black87, - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 17), - child: Column( - children: [ - const SizedBox( - height: 20, - ), - Row( - children: [ - TextAtom( - 'Settings', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 18, - ), - ), - ], - ), - Divider( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - Row( - children: [ - Container( - alignment: Alignment.center, - child: ImageAtom( - 'assets/cbj_half_app_logo.png', - width: 70.0, - ), - ), - const SizedBox( - width: 20, - ), - TextAtom( - 'CyBear Jinni', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 20, - ), - ), - ], - ), - const SizedBox( - height: 40, - ), - ], - ), - ), - ), - SingleChildScrollView( - reverse: true, - child: Column( - children: [ - Divider( - thickness: 0.5, - height: 0.5, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ColoredBox( - color: Colors.greenAccent.withOpacity(0.8), - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.rightToBracket, - color: Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Log Out', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - onTap: () { - _fireBaseLogOut(context); - }, - ), - ), - Divider( - thickness: 0.5, - height: 0.5, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ColoredBox( - color: Colors.orangeAccent, - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.info, - color: Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Software Info', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - onTap: () { - context.router.push(const SoftwareInfoRoute()); - }, - ), - ), - Divider( - thickness: 0.5, - height: 0.5, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ColoredBox( - color: Colors.blue, - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.globe, - color: Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Add Remote Control Support', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - onTap: () { - context.router.push(const RemotePipesRoute()); - }, - ), - ), - Divider( - thickness: 0.5, - height: 0.5, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - // Container( - // color: Colors.redAccent, - // child: ListTile( - // leading: FaIcon( - // FontAwesomeIcons.userPlus, - // color: Theme.of(context).textTheme.bodyLarge!.color, - // size: 25, - // ), - // title: TextAtom( - // 'Manage Users', - // style: TextStyle( - // color: Theme.of(context).textTheme.bodyLarge!.color, - // ), - // ), - // onTap: () { - // context.router.push(const ManageUsersRoute()); - // }, - // ), - // ), - // Divider( - // thickness: 0.5, - // height: 0.5, - // color: Theme.of(context).textTheme.bodyLarge!.color, - // ), - ], - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart index 9bcb09d6d..a89b88c0c 100644 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart +++ b/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart @@ -40,7 +40,6 @@ class AddBindingsPage extends StatelessWidget { TopNavigationBar( pageName: 'Add Binding', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart index d9ab2ce48..c290cf2d1 100644 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart +++ b/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart @@ -66,7 +66,7 @@ class BindingsPage extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart index 76a8ae569..0bf041820 100644 --- a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart +++ b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart @@ -14,7 +14,7 @@ class ScenesInFoldersL extends StatelessWidget { return state.map( (value) => const TextAtom('sd'), loading: (_) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loaded: (state) { return ListView.builder( diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart index 00a2cc5b3..024a37fb8 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/security_cameras_in_the_room_block.dart @@ -51,9 +51,12 @@ class SecurityCamerasInTheRoomBlock extends StatelessWidget { return GestureDetector( onTap: () { - context.router.push(VideoStreamOutputContainerRoute( + context.router.push( + VideoStreamOutputContainerRoute( streamAddress: - securityCamerasInRoom.first.deviceLastKnownIp.getOrCrash())); + securityCamerasInRoom.first.deviceLastKnownIp.getOrCrash(), + ), + ); }, child: Container( decoration: BoxDecoration( @@ -76,7 +79,7 @@ class SecurityCamerasInTheRoomBlock extends StatelessWidget { scale: 1.2, child: const CircleAvatar( child: FaIcon( - FontAwesomeIcons.print, + FontAwesomeIcons.camera, color: Colors.white70, ), ), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart index e958bb94a..65bce1560 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart @@ -133,13 +133,13 @@ class RoomWidget extends StatelessWidget { if (numberOfDevicesInTheRoom == 1) TextAtom( '_device', - style: TextStyle(fontSize: 12), + style: const TextStyle(fontSize: 12), translationArgs: [numberOfDevicesInTheRoom.toString()], ) else TextAtom( '_devices', - style: TextStyle(fontSize: 12), + style: const TextStyle(fontSize: 12), translationArgs: [numberOfDevicesInTheRoom.toString()], ), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart index 62268bbe8..18acf8ee7 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/settings_page_of_smart_devices.dart @@ -39,7 +39,6 @@ class SettingsPageSmartDevices extends StatelessWidget { TopNavigationBar( pageName: 'Smart Devices Settings', rightIcon: null, - rightIconFunction: () {}, leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart index 251b0b545..e6c65785a 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart @@ -17,7 +17,7 @@ class SmartDevicesByRooms extends StatelessWidget { loadInProgress: (_) => const Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - CircularProgressIndicator(), + CircularProgressIndicatorAtom(), SizedBox( height: 30, ), @@ -46,7 +46,7 @@ class SmartDevicesByRooms extends StatelessWidget { Container( margin: const EdgeInsets.only(bottom: 10), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', width: 200.0, fit: BoxFit.fill, @@ -110,7 +110,7 @@ class SmartDevicesByRooms extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 30), alignment: Alignment.center, - child: ImageAtom( + child: const ImageAtom( 'assets/cbj_logo.png', fit: BoxFit.fitHeight, ), diff --git a/lib/presentation/pages/introduction_screen/introduction_screen_body.dart b/lib/presentation/pages/introduction_screen/introduction_screen_body.dart index 35e31aa21..4e4c03573 100644 --- a/lib/presentation/pages/introduction_screen/introduction_screen_body.dart +++ b/lib/presentation/pages/introduction_screen/introduction_screen_body.dart @@ -44,7 +44,7 @@ class IntroductionScreenBody extends StatelessWidget { children: [ Container( margin: const EdgeInsets.only(top: 20, bottom: 5), - child: Center( + child: const Center( child: ImageAtom( 'assets/cbj_logo.png', height: 200.0, diff --git a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart b/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart index b679c2f2e..358c2b7bc 100644 --- a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart +++ b/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart @@ -16,10 +16,7 @@ class JoinHomeByIdWidget extends StatelessWidget { state.map( (value) => null, loading: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); + return const CircularProgressIndicatorAtom(); }, loaded: (l) { return const TextAtom('Loaded'); @@ -113,10 +110,7 @@ class JoinHomeByIdWidget extends StatelessWidget { state.map( (value) => const SizedBox(), loading: (_) { - return const CircularProgressIndicator( - backgroundColor: Colors.cyan, - strokeWidth: 5, - ); + return const CircularProgressIndicatorAtom(); }, loaded: (l) { context.router.replace(const HomeRoute()); diff --git a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart b/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart index e4964f80e..dbb6cfd9e 100644 --- a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart +++ b/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart @@ -15,7 +15,7 @@ class ManageUsersWidget extends StatelessWidget { return state.map( initial: (_) => Container(), inProgress: (state) => const Center( - child: CircularProgressIndicator(), + child: CircularProgressIndicatorAtom(), ), loadSuccess: (state) { return Container( diff --git a/lib/presentation/pages/plus_button/plus_button.dart b/lib/presentation/pages/plus_button/plus_button.dart index 36381d95e..d588d098c 100644 --- a/lib/presentation/pages/plus_button/plus_button.dart +++ b/lib/presentation/pages/plus_button/plus_button.dart @@ -1,10 +1,7 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/plus_button_settings/plus_button_settings_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/plus_button/widgets/plus_button_wighet.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() class PlusButtonPage extends StatelessWidget { @@ -16,13 +13,7 @@ class PlusButtonPage extends StatelessWidget { backgroundColor: Colors.purple.withOpacity(0.7), ), backgroundColor: Colors.black.withOpacity(0.7), - body: BlocProvider( - create: (BuildContext context) => getIt() - ..add( - PlusButtonSettingsEvent.initialized(context), - ), - child: PlusButtonWidget(), - ), + body: PlusButtonWidget(), ); } } diff --git a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart index dead13c5a..94152b1a4 100644 --- a/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart +++ b/lib/presentation/pages/plus_button/widgets/plus_button_wighet.dart @@ -1,343 +1,246 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/plus_button_settings/plus_button_settings_bloc.dart'; -import 'package:cybear_jinni/domain/hub/hub_entity.dart'; +import 'package:cbj_integrations_controller/domain/hub/hub_entity.dart'; import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:iconify_flutter/iconify_flutter.dart'; import 'package:iconify_flutter/icons/simple_icons.dart'; import 'package:url_launcher/url_launcher.dart'; class PlusButtonWidget extends StatelessWidget { + Future _logout(BuildContext context) async { + context.router.replace(const ConnectToHubRoute()); + await IHubConnectionRepository.instance.closeConnection(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) { - return SingleChildScrollView( - child: Column( - children: [ - const SizedBox( - height: 30, - ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 15), - alignment: Alignment.topLeft, - child: const TextAtom( - 'Add:', + return SingleChildScrollView( + child: Column( + children: [ + const SizedBox( + height: 30, + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 15), + alignment: Alignment.topLeft, + child: const TextAtom( + 'Add:', + style: TextStyle( + color: Colors.white, + fontSize: 20, + ), + ), + ), + const SizedBox( + height: 10, + ), + ColoredBox( + color: Colors.white, + child: Column( + children: [ + const SizedBox(height: 1), + ColoredBox( + color: Colors.indigoAccent.withOpacity(0.7), + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.sitemap, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: TextAtom( + 'Turn Phone To a Security Camera', style: TextStyle( - color: Colors.white, - fontSize: 20, + color: Theme.of(context).textTheme.bodyLarge!.color, ), ), + onTap: () async { + context.router.push(const SmartCameraContainerRoute()); + await IHubConnectionRepository.instance.closeConnection(); + }, ), - const SizedBox( - height: 10, - ), - ColoredBox( - color: Colors.white, - child: Column( - children: [ - const SizedBox(height: 1), - ColoredBox( - color: Colors.indigoAccent.withOpacity(0.7), - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.sitemap, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Turn Phone To a Security Camera', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () async { - await IHubConnectionRepository.instance - .closeConnection(); - - context.router - .push(const SmartCameraContainerRoute()); - }, - ), - ), - const SizedBox( - height: 1, - ), - ColoredBox( - color: Colors.brown.withOpacity(0.9), - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.solidLightbulb, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Add Device', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () { - context.router - .push(const ChooseDeviceVendorToAddRoute()); - }, - ), - ), - const SizedBox(height: 1), - ColoredBox( - color: Colors.blue, - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.globe, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Add Remote Control Support', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () { - context.router.push(const RemotePipesRoute()); - }, - ), - ), - const SizedBox(height: 1), - ColoredBox( - color: Colors.purple.withOpacity(0.7), - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.sitemap, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Add Automation', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () { - context.router - .push(const ChooseAutomationTypeToAddRoute()); - }, - ), - ), - const SizedBox(height: 1), - ], + ), + const SizedBox( + height: 1, + ), + ColoredBox( + color: Colors.brown.withOpacity(0.9), + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.solidLightbulb, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, ), + title: TextAtom( + 'Add Device', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + onTap: () { + context.router.push(const ChooseDeviceVendorToAddRoute()); + }, ), - const SizedBox( - height: 40, - ), - Container( - alignment: Alignment.topLeft, - padding: const EdgeInsets.symmetric(horizontal: 15), - child: const TextAtom( - 'Manage:', + ), + const SizedBox(height: 1), + ColoredBox( + color: Colors.blue, + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.globe, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: TextAtom( + 'Add Remote Control Support', style: TextStyle( - color: Colors.white, - fontSize: 20, + color: Theme.of(context).textTheme.bodyLarge!.color, ), ), + onTap: () { + context.router.push(const RemotePipesRoute()); + }, ), - const SizedBox( - height: 10, + ), + const SizedBox(height: 1), + ColoredBox( + color: Colors.purple.withOpacity(0.7), + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.sitemap, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: TextAtom( + 'Add Automation', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + onTap: () { + context.router + .push(const ChooseAutomationTypeToAddRoute()); + }, ), - ColoredBox( - color: Colors.white, - child: Column( - children: [ - const SizedBox( - height: 1, - ), - ColoredBox( - color: Colors.redAccent.withOpacity(0.9), - child: ListTile( - leading: Iconify( - SimpleIcons.node_red, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 23, - ), - title: TextAtom( - 'Open Node-RED of Hub', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () { - final HubEntity? hubEntity = - IHubConnectionRepository.hubEntity; - if (hubEntity != null && - hubEntity.lastKnownIp.isValid()) { - final String lastKnownIp = - hubEntity.lastKnownIp.getOrCrash(); - launchUrl( - Uri.parse('http://$lastKnownIp:1880'), - mode: LaunchMode.externalApplication, - ); - } else { - showDialog( - context: context, - builder: (_) => const AlertDialog( - title: TextAtom( - "Can't find Hub/Node-Red IP to connect to", - ), - ), - ); - } - }, - ), - ), - const SizedBox( - height: 1, - ), - ColoredBox( - color: Colors.orangeAccent, - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.info, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), - title: TextAtom( - 'Software Info', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - onTap: () { - context.router.push(const SoftwareInfoRoute()); - }, - ), - ), - const SizedBox( - height: 1, - ), - ColoredBox( - color: Colors.greenAccent, - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.rightFromBracket, - color: - Theme.of(context).textTheme.bodyLarge!.color, - size: 25, - ), + ), + const SizedBox(height: 1), + ], + ), + ), + const SizedBox( + height: 40, + ), + Container( + alignment: Alignment.topLeft, + padding: const EdgeInsets.symmetric(horizontal: 15), + child: const TextAtom( + 'Manage:', + style: TextStyle( + color: Colors.white, + fontSize: 20, + ), + ), + ), + const SizedBox( + height: 10, + ), + ColoredBox( + color: Colors.white, + child: Column( + children: [ + const SizedBox( + height: 1, + ), + ColoredBox( + color: Colors.redAccent.withOpacity(0.9), + child: ListTile( + leading: Iconify( + SimpleIcons.node_red, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 23, + ), + title: TextAtom( + 'Open Node-RED of Hub', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + onTap: () { + final HubEntity? hubEntity = + IHubConnectionRepository.hubEntity; + if (hubEntity != null && + hubEntity.lastKnownIp.isValid()) { + final String lastKnownIp = + hubEntity.lastKnownIp.getOrCrash(); + launchUrl( + Uri.parse('http://$lastKnownIp:1880'), + mode: LaunchMode.externalApplication, + ); + } else { + showDialog( + context: context, + builder: (_) => const AlertDialog( title: TextAtom( - 'Log Out', - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), + "Can't find Hub/Node-Red IP to connect to", ), - onTap: () { - context.read().add( - const PlusButtonSettingsEvent.logout(), - ); - }, ), - ), - const SizedBox( - height: 1, - ), - ], + ); + } + }, + ), + ), + const SizedBox( + height: 1, + ), + ColoredBox( + color: Colors.orangeAccent, + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.info, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: TextAtom( + 'Software Info', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), ), + onTap: () { + context.router.push(const SoftwareInfoRoute()); + }, ), - ], - ), - ); - }, - loadInProgress: (_) => const Center( - child: CircularProgressIndicator(), + ), + const SizedBox( + height: 1, + ), + ColoredBox( + color: Colors.greenAccent, + child: ListTile( + leading: FaIcon( + FontAwesomeIcons.rightFromBracket, + color: Theme.of(context).textTheme.bodyLarge!.color, + size: 25, + ), + title: TextAtom( + 'Log Out', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + onTap: () => _logout(context), + ), + ), + const SizedBox( + height: 1, + ), + ], + ), ), - loadSuccess: (_) => const TextAtom('Found hub'), - loadFailure: (failure) => const TextAtom('Failure'), - ); - }, + ], + ), ); } } - -// -// GestureDetector( -// onTap: () { -// -// await IHubConnectionRepository.instance.closeConnection(); -// -// event.context.router.push(const SmartCameraContainerRoute()); -// }, -// child: Container( -// margin: const EdgeInsets.symmetric(horizontal: 30), -// height: 60, -// color: HexColor('#985dc7'), -// child: Container( -// margin: const EdgeInsets.symmetric(horizontal: 15), -// child: Row( -// children: [ -// const FaIcon( -// FontAwesomeIcons.camera, -// color: Colors.white, -// ), -// const SizedBox( -// width: 40, -// ), -// Flexible( -// child: RichText( -// text: TextSpan( -// style: TextStyle( -// color: Colors.white.withOpacity(0.9), -// ), -// children: const [ -// TextSpan( -// text: 'Security Camera\n', -// style: TextStyle(fontSize: 16), -// ), -// TextSpan( -// text: -// 'Transform your phone into a smart security camera', -// style: TextStyle( -// color: Colors.white, -// ), -// ), -// ], -// ), -// ), -// ), -// ], -// ), -// ), -// ), -// ), diff --git a/lib/presentation/pages/routes/app_router.dart b/lib/presentation/pages/routes/app_router.dart index cb14ae8e3..7f7c60dff 100644 --- a/lib/presentation/pages/routes/app_router.dart +++ b/lib/presentation/pages/routes/app_router.dart @@ -9,10 +9,8 @@ class AppRouter extends $AppRouter { AutoRoute(page: IntroductionRouteRoute.page), AutoRoute(page: ConnectToHubRoute.page), AutoRoute(page: ConnectToHubMoreRoute.page), - AutoRoute(page: SignInRoute.page), AutoRoute(page: CreateHomeRoute.page), - AutoRoute(page: WhereToLoginRouteMinimalRoute.page), - AutoRoute(page: WhereToLoginRouteOffline.page), + AutoRoute(page: ChooseDeviceVendorToAddRoute.page), AutoRoute(page: JoinHomeByIdRoute.page), AutoRoute(page: HomeRoute.page), AutoRoute(page: ChangeRoomForDevicesRoute.page), @@ -32,11 +30,7 @@ class AppRouter extends $AppRouter { AutoRoute(page: ChooseDeviceVendorToAddRoute.page), AutoRoute(page: AddLifxVendorRoute.page), AutoRoute(page: AddEspHomeVendorRoute.page), - AutoRoute(page: AddXiaomiMiVendorRoute.page), AutoRoute(page: AddEwelinkVendorRoute.page), - AutoRoute(page: AddTuyaVendorRoute.page), - AutoRoute(page: AddSmartLifeVendorRoute.page), - AutoRoute(page: AddJinvooSmartVendorRoute.page), AutoRoute(page: ConnectToHomeWifiRoute.page), AutoRoute(page: OpenAccessPointRoute.page), AutoRoute(page: ScanForNewCBJCompsRoute.page), diff --git a/lib/presentation/pages/scenes/scenes_page.dart b/lib/presentation/pages/scenes/scenes_page.dart index 55f182f55..00392e2aa 100644 --- a/lib/presentation/pages/scenes/scenes_page.dart +++ b/lib/presentation/pages/scenes/scenes_page.dart @@ -76,7 +76,7 @@ class ScenesPage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: leftIconFunction, // rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - // rightSecondFunction: () {}, + // ), Expanded( child: BlocProvider( diff --git a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart index 1c4768997..f70ac21b4 100644 --- a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart +++ b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart @@ -16,10 +16,10 @@ class FolderOfScenesWidget extends StatelessWidget { final RoomEntity folderOfScenes; - SceneCbjEntity getTheScen( + SceneCbjEntity getTheScene( Either scenesList, ) { - return scenesList.fold((l) => null!, (r) => r); + return scenesList.fold((l) => throw 'Invalid value', (r) => r); } @override diff --git a/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart b/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart index a81fc73a3..4215cee9e 100644 --- a/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart +++ b/lib/presentation/pages/shared_widgets/add_new_devie_widget.dart @@ -38,12 +38,12 @@ class _AddNewDeviceWidgetPopup extends State { } return null; }, - decoration: InputDecoration( - labelText: 'IP' + decoration: const InputDecoration( + labelText: 'IP', ), ); } else { - return const CircularProgressIndicator(); + return const CircularProgressIndicatorAtom(); } }, ), diff --git a/lib/presentation/pages/shared_widgets/top_navigation_bar.dart b/lib/presentation/pages/shared_widgets/top_navigation_bar.dart index 5814d1e62..9d5aed694 100644 --- a/lib/presentation/pages/shared_widgets/top_navigation_bar.dart +++ b/lib/presentation/pages/shared_widgets/top_navigation_bar.dart @@ -8,7 +8,7 @@ class TopNavigationBar extends StatelessWidget { const TopNavigationBar({ required this.pageName, required this.rightIcon, - required this.rightIconFunction, + this.rightIconFunction, this.leftIcon, this.leftIconFunction, this.rightSecondIcon, @@ -30,13 +30,13 @@ class TopNavigationBar extends StatelessWidget { final IconData? leftIcon; /// Function to execute when pressing the icon in the right side - final Function? rightIconFunction; + final Function(BuildContext)? rightIconFunction; /// What to execute if second right icon was pressed - final Function? rightSecondFunction; + final Function(BuildContext)? rightSecondFunction; /// What to execute if back button was pressed - final Function? leftIconFunction; + final Function(BuildContext)? leftIconFunction; final Color? backgroundColor; @@ -73,7 +73,8 @@ class TopNavigationBar extends StatelessWidget { fontSize: 16.0, color: Theme.of(context).textTheme.bodyLarge!.color, ), - ), ], + ), + ], ), if (rightIcon != null) Row( diff --git a/lib/presentation/pages/sign_in_page/sign_in_page.dart b/lib/presentation/pages/sign_in_page/sign_in_page.dart deleted file mode 100644 index e63781145..000000000 --- a/lib/presentation/pages/sign_in_page/sign_in_page.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/sign_in_form/sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class SignInPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const TextAtom('Sign In'), - ), - body: BlocProvider( - create: (context) => getIt(), - child: SignInFormWidget(), - ), - ); - } -} diff --git a/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart b/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart deleted file mode 100644 index c8d8c38b9..000000000 --- a/lib/presentation/pages/sign_in_page/widgets/sign_in_form_widget.dart +++ /dev/null @@ -1,169 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; -import 'package:cybear_jinni/application/auth/sign_in_form/sign_in_form_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class SignInFormWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - final Size screenSize = MediaQuery.of(context).size; - - return BlocConsumer( - listener: (context, state) { - state.authFailureOrSuccessOption.fold( - () {}, - (either) => either.fold( - (failure) => { - FlushbarHelper.createError( - message: failure.map( - cancelledByUser: (_) => 'Cancelled', - serverError: (_) => 'Server error', - emailAlreadyInUse: (_) => 'Email already in use', - invalidEmailAndPasswordCombination: (_) => - 'Invalid email and password combination', - ), - ).show(context), - }, (_) { - context.router.push(const WhereToLoginRouteMinimalRoute()); - - context - .read()() - .add(const AuthEvent.authCheckRequested()); - }), - ); - }, - builder: (context, state) { - return Column( - children: [ - Expanded( - child: Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: ListView( - padding: const EdgeInsets.all(8), - children: [ - Hero( - tag: 'hero', - child: CircleAvatar( - backgroundColor: Colors.transparent, - radius: screenSize.height * 0.1, - child: ImageAtom('assets/cbj_logo.png'), - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: Icon(Icons.email), - labelText: 'Email', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(SignInFormEvent.emailChanged(value)), - validator: (_) => context - .read() - .state - .emailAddress - .value - .fold( - (f) => f.maybeMap( - invalidEmail: (result) => result.failedValue, - containsSpace: (result) => result.failedValue, - orElse: () => null, - ), - (r) => null, - ), - ), - const SizedBox( - height: 8, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: Icon(Icons.lock), - labelText: 'Password', - ), - autocorrect: false, - obscureText: true, - onChanged: (value) => context - .read() - .add(SignInFormEvent.passwordChanged(value)), - validator: (_) => context - .read() - .state - .password - .value - .fold( - (f) => f.maybeMap( - shortPassword: (result) => result.failedValue, - containsSpace: (result) => result.failedValue, - orElse: () => null, - ), - (r) => null, - ), - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const SignInFormEvent - .signInWithEmailAndPasswordPassed(), - ); - }, - child: const TextAtom('SIGN IN'), - ), - ), - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const SignInFormEvent - .registerWithEmailAndPassword(), - ); - }, - child: const TextAtom('REGISTER'), - ), - ), - ], - ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, - ), - const LinearProgressIndicator(), - ], - ], - ), - ), - ), - Container( - alignment: Alignment.bottomRight, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - onPressed: () { - context.router.push(const WhereToLoginRouteOffline()); - }, - child: TextAtom( - 'For More Options', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/software_info/software_info_page.dart b/lib/presentation/pages/software_info/software_info_page.dart index 67123adb0..cae0fa4a9 100644 --- a/lib/presentation/pages/software_info/software_info_page.dart +++ b/lib/presentation/pages/software_info/software_info_page.dart @@ -1,8 +1,6 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cybear_jinni/application/auth/auth_bloc.dart'; -import 'package:cybear_jinni/application/software_info/software_info_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; @@ -38,49 +36,41 @@ class SoftwareInfoPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const SoftwareInfoEvent.initialized()), + return MultiBlocListener( + listeners: [ + BlocListener( + listener: (context, state) { + state.maybeMap( + unauthenticated: (_) => + context.router.replace(const ConnectToHubRoute()), + orElse: () {}, + ); + }, ), ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.light, - ), + child: Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: const SystemUiOverlayStyle( + statusBarIconBrightness: Brightness.light, ), - body: ColoredBox( - color: Colors.black87, - child: Column( - children: [ - TopNavigationBar( - pageName: 'Software Info', - rightIcon: null, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, - ), - Expanded( - child: SoftwareInfoWidget(), - ), - ], - ), + ), + body: ColoredBox( + color: Colors.black87, + child: Column( + children: [ + TopNavigationBar( + pageName: 'Software Info', + rightIcon: null, + rightIconFunction: userCogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: leftIconFunction, + ), + Expanded( + child: SoftwareInfoWidget(), + ), + ], ), ), ), diff --git a/lib/presentation/pages/software_info/widgets/software_info_widget.dart b/lib/presentation/pages/software_info/widgets/software_info_widget.dart index 0e2997cdd..40c94e363 100644 --- a/lib/presentation/pages/software_info/widgets/software_info_widget.dart +++ b/lib/presentation/pages/software_info/widgets/software_info_widget.dart @@ -1,132 +1,174 @@ -import 'package:cybear_jinni/application/software_info/software_info_bloc.dart'; +import 'package:cybear_jinni/domain/software_info/i_software_info_repository.dart'; import 'package:cybear_jinni/domain/software_info/software_info_entity.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; /// Show light toggles in a container with the background color from smart room /// object -class SoftwareInfoWidget extends StatelessWidget { +class SoftwareInfoWidget extends StatefulWidget { + @override + State createState() => _SoftwareInfoWidgetState(); +} + +class _SoftwareInfoWidgetState extends State { + Map softwaresInfo = {}; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + SoftwareInfoEntity? appInfoEntity; + (await ISoftwareInfoRepository.instance.getAppSoftwareInfo()).fold( + (l) => l, + (r) { + appInfoEntity = r; + }, + ); + + if (appInfoEntity != null) { + setState(() { + softwaresInfo.addEntries([MapEntry('App Server', appInfoEntity!)]); + }); + } + + SoftwareInfoEntity? hubInfoEntity; + (await ISoftwareInfoRepository.instance.getHubSoftwareInfo()).fold( + (l) => l, + (r) { + hubInfoEntity = r; + }, + ); + + if (hubInfoEntity != null) { + setState(() { + softwaresInfo.addEntries([MapEntry('Hub Server', hubInfoEntity!)]); + }); + } + + SoftwareInfoEntity? securityBearInfoEntity; + (await ISoftwareInfoRepository.instance.getSecurityBearSoftwareInfo()).fold( + (l) => l, + (r) { + securityBearInfoEntity = r; + }, + ); + + if (securityBearInfoEntity != null) { + setState(() { + softwaresInfo.addEntries([ + MapEntry('Security Bear Server', securityBearInfoEntity!), + ]); + }); + } + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (Initial value) { - return const Center(child: CircularProgressIndicator()); - }, - gotSoftwareInfoEntities: (GotSoftwareInfoEntities value) { - final Map softwareInfoEntities = - value.softwareInfoEntities; + if (softwaresInfo.isEmpty) { + return const CircularProgressIndicatorAtom(); + } - return ListView.builder( - itemCount: softwareInfoEntities.length, - padding: const EdgeInsets.all(30), - itemBuilder: (context, i) { - final String key = softwareInfoEntities.keys.elementAt(i); - final SoftwareInfoEntity? softwareInfoEntity = - softwareInfoEntities[key]; - return Column( - children: [ - TextAtom( - key, - style: const TextStyle(fontSize: 26), + return ListView.builder( + itemCount: softwaresInfo.length, + padding: const EdgeInsets.all(30), + itemBuilder: (context, i) { + final String key = softwaresInfo.keys.elementAt(i); + final SoftwareInfoEntity? softwareInfoEntity = softwaresInfo[key]; + return Column( + children: [ + TextAtom( + key, + style: const TextStyle(fontSize: 26), + ), + ListTileTheme( + textColor: Theme.of(context).textTheme.bodyLarge!.color, + child: Column( + children: [ + ListTile( + title: Row( + children: [ + const TextAtom('Device name: '), + TextAtom( + softwareInfoEntity?.deviceName.getOrCrash() ?? + 'No Info', + ), + ], ), - ListTileTheme( - textColor: Theme.of(context).textTheme.bodyLarge!.color, - child: Column( - children: [ - ListTile( - title: Row( - children: [ - const TextAtom('Device name: '), - TextAtom( - softwareInfoEntity?.deviceName.getOrCrash() ?? - 'No Info', - ), - ], - ), - ), - ListTile( - title: Row( - children: [ - const TextAtom('Pubspec yaml version: '), - TextAtom( - softwareInfoEntity?.pubspecYamlVersion - .getOrCrash() ?? - 'No Info', - ), - ], - ), - ), - ListTile( - title: Row( - children: [ - const TextAtom('Proto last gen date: '), - TextAtom( - softwareInfoEntity?.protoLastGenDate - .getOrCrash() ?? - 'No Info', - ), - ], - ), - ), - ListTile( - title: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const TextAtom('Dart SDK version: '), - Flexible( - child: TextAtom( - softwareInfoEntity?.dartSdkVersion - .getOrCrash() ?? - 'No Info', - ), - ), - ], - ), - ), - ListTile( - title: Row( - children: [ - const TextAtom('Comp id: '), - TextAtom( - softwareInfoEntity?.compId.getOrCrash() ?? - 'No Info', - ), - ], - ), - ), - ListTile( - title: Row( - children: [ - const TextAtom('Comp uuid: '), - TextAtom( - softwareInfoEntity?.compUuid.getOrCrash() ?? - 'No Info', - ), - ], - ), - ), - ListTile( - title: Row( - children: [ - const TextAtom('Comp os: '), - TextAtom( - softwareInfoEntity?.compOs.getOrCrash() ?? - 'No Info', - ), - ], - ), + ), + ListTile( + title: Row( + children: [ + const TextAtom('Pubspec yaml version: '), + TextAtom( + softwareInfoEntity?.pubspecYamlVersion.getOrCrash() ?? + 'No Info', + ), + ], + ), + ), + ListTile( + title: Row( + children: [ + const TextAtom('Proto last gen date: '), + TextAtom( + softwareInfoEntity?.protoLastGenDate.getOrCrash() ?? + 'No Info', + ), + ], + ), + ), + ListTile( + title: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const TextAtom('Dart SDK version: '), + Flexible( + child: TextAtom( + softwareInfoEntity?.dartSdkVersion.getOrCrash() ?? + 'No Info', ), - ], - ), + ), + ], + ), + ), + ListTile( + title: Row( + children: [ + const TextAtom('Comp id: '), + TextAtom( + softwareInfoEntity?.compId.getOrCrash() ?? 'No Info', + ), + ], + ), + ), + ListTile( + title: Row( + children: [ + const TextAtom('Comp uuid: '), + TextAtom( + softwareInfoEntity?.compUuid.getOrCrash() ?? + 'No Info', + ), + ], + ), + ), + ListTile( + title: Row( + children: [ + const TextAtom('Comp os: '), + TextAtom( + softwareInfoEntity?.compOs.getOrCrash() ?? 'No Info', + ), + ], ), - ], - ); - }, - ); - }, + ), + ], + ), + ), + ], ); }, ); diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart deleted file mode 100644 index dcfb17caf..000000000 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/where_to_login_page_minimal_page.dart +++ /dev/null @@ -1,175 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; -import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// The user will choose where to login to, join into an existing home or -/// create his new home -@RoutePage() -class WhereToLoginPageMinimalPage extends StatelessWidget { - const WhereToLoginPageMinimalPage(); - - void backButtonFunction(BuildContext context) { - Navigator.pop(context); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.deepPurpleAccent[200]!.withOpacity(0.6), - title: const TextAtom('Choose type of login'), - ), - body: Column( - children: [ - const SizedBox( - height: 30, - ), - Container( - width: MediaQuery.of(context).size.width - 20, - decoration: const BoxDecoration( - color: Colors.black38, - borderRadius: BorderRadius.all(Radius.circular(10)), - ), - alignment: Alignment.center, - child: TextAtom( - 'What would you like to do', - style: TextStyle( - fontSize: 25, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - Expanded( - child: Column( - children: [ - const SizedBox( - height: 30, - ), - SizedBox( - height: 100, - width: MediaQuery.of(context).size.width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.blue, - ), - ), - onPressed: () { - context.router.push(const CreateHomeRoute()); - }, - child: Container( - margin: const EdgeInsets.only(left: 30), - child: Row( - children: [ - FaIcon( - FontAwesomeIcons.doorOpen, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - const SizedBox( - width: 20, - ), - TextAtom( - 'Create Your Home', - style: TextStyle( - fontSize: 25, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - ), - ), - ), - const SizedBox( - height: 10, - ), - SizedBox( - height: 100, - width: MediaQuery.of(context).size.width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.orange, - ), - ), - onPressed: () { - context.router.push(const JoinHomeByIdRoute()); - }, - child: Container( - margin: const EdgeInsets.only(left: 30), - child: Row( - children: [ - FaIcon( - FontAwesomeIcons.userGroup, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - const SizedBox( - width: 20, - ), - TextAtom( - 'Join Existing Home', - style: TextStyle( - fontSize: 25, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - ), - ), - ), - Container( - margin: const EdgeInsets.only(top: 10), - width: double.infinity, - color: Colors.black87, - child: const Center( - child: TextAtom( - 'Homes you have add', - style: TextStyle(fontSize: 20), - ), - ), - ), - MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const UserHomesListEvent.watchAllStarted()), - ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => context.router - .replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), - ], - child: Expanded( - child: ColoredBox( - color: Colors.black54, - child: UserHomesListWidget(), - ), - ), - ), - ), - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart deleted file mode 100644 index 2ac570874..000000000 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:flutter/material.dart'; - -class ErrorHomeCard extends StatelessWidget { - const ErrorHomeCard({ - required this.home, - super.key, - }); - - final AllHomesOfUserEntity? home; - - @override - Widget build(BuildContext context) { - return Card( - color: Theme.of(context).colorScheme.error, - child: Padding( - padding: const EdgeInsets.all(4), - child: Column( - children: [ - TextAtom( - 'Invalid user, please, contact support', - style: Theme.of(context) - .primaryTextTheme - .bodyMedium! - .copyWith(fontSize: 18), - ), - const SizedBox(height: 2), - TextAtom( - 'Details for nerds:', - style: Theme.of(context).primaryTextTheme.bodyMedium, - ), - TextAtom( - home!.failureOption.fold(() => '', (f) => f.toString()), - style: Theme.of(context).primaryTextTheme.bodyMedium, - ), - ], - ), - ), - ); - } -} diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart deleted file mode 100644 index 149f6f5b1..000000000 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class HomeCardWidget extends StatelessWidget { - const HomeCardWidget({ - required this.home, - super.key, - }); - - final AllHomesOfUserEntity? home; - - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - state.map( - initial: (_) => const TextAtom('initial'), - loadInProgress: (_) => const TextAtom('loadInProgress'), - loadSuccess: (_) => const TextAtom('loadInSuccess'), - enterHome: (_) { - context.router.replace(const HomeRoute()); - }, - loadFailure: (_) => const TextAtom('loadFailure'), - loadFailureEnteringHome: (_) => FlushbarHelper.createError( - message: "Can't enter this home", - ), - error: (_) => const TextAtom('error'), - ); - return TextButton( - onPressed: () { - context - .read() - .add(UserHomesListEvent.joinExistingHome(home)); - }, - child: Container( - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - bottom: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - ), - ), - height: 100, - child: Center( - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.houseUser, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextAtom( - home!.name!.getOrCrash()!, - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - ), - ), - ), - ); - }, - ); - } -} diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart deleted file mode 100644 index d49a34f24..000000000 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/user_homes_list_widget.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:cybear_jinni/application/user_homes_list/user_homes_list_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/error_home_card_widget.dart'; -import 'package:cybear_jinni/presentation/pages/where_to_login_page/where_to_login_page_minimal/widgets/home_card_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class UserHomesListWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Expanded( - child: state.map( - initial: (_) => Container(), - loadInProgress: (state) => const Center( - child: CircularProgressIndicator(), - ), - loadSuccess: (state) { - return ListView.builder( - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final homeUser = state.homes[index]; - if (homeUser.failureOption.isSome()) { - return ErrorHomeCard(home: homeUser); - } else { - return BlocProvider( - create: (context) => getIt(), - child: HomeCardWidget(home: homeUser), - ); - } - }, - itemCount: state.homes.size, - ); - }, - loadFailure: (state) { - return const TextAtom('Load Failure'); - }, - error: (state) { - return const TextAtom('Error'); - }, - enterHome: (e) { - return const TextAtom('Entering Home'); - }, - loadFailureEnteringHome: (f) { - FlushbarHelper.createError( - message: "Can't enter this home", - ); - return const TextAtom('Failure'); - }, - ), - ); - }, - ); - } -} diff --git a/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart b/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart deleted file mode 100644 index a4a0025e3..000000000 --- a/lib/presentation/pages/where_to_login_page/where_to_login_page_offline.dart +++ /dev/null @@ -1,137 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// The user will choose where to login to, options only for offline -@RoutePage() -class WhereToLoginPageOffline extends StatelessWidget { - const WhereToLoginPageOffline(); - - void leftIconFunction(BuildContext context) { - Navigator.pop(context); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const TextAtom('Choose type of login'), - ), - backgroundColor: Colors.deepPurpleAccent[200]!.withOpacity(0.6), - body: Column( - children: [ - const SizedBox( - height: 30, - ), - Container( - width: MediaQuery.of(context).size.width - 20, - decoration: const BoxDecoration( - color: Colors.black38, - borderRadius: BorderRadius.all(Radius.circular(10)), - ), - alignment: Alignment.center, - child: TextAtom( - 'What would you like to do', - style: TextStyle( - fontSize: 25, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - Expanded( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - height: 100, - width: MediaQuery.of(context).size.width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.greenAccent, - ), - ), - onPressed: () { - context.router.push(const HomeRoute()); - }, - child: Container( - margin: const EdgeInsets.only(left: 30), - child: Row( - children: [ - FaIcon( - FontAwesomeIcons.vial, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - const SizedBox( - width: 20, - ), - TextAtom( - 'Open Demo', - style: TextStyle( - fontSize: 25, - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - ], - ), - ), - ), - ), - const SizedBox( - height: 10, - ), - SizedBox( - height: 100, - width: MediaQuery.of(context).size.width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.brown, - ), - ), - onPressed: () { - context.router.replace(const HomeRoute()); - }, - child: Container( - margin: const EdgeInsets.only(left: 30), - child: Row( - children: [ - FaIcon( - FontAwesomeIcons.tree, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - const SizedBox( - width: 20, - ), - TextAtom( - 'Work Only On WiFi', - style: TextStyle( - fontSize: 25, - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), - ), - ], - ), - ), - ), - ), - ], - ), - ), - ), - ], - ), - ); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index eac6fbc2c..e2be039aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -127,6 +127,7 @@ dependencies: # The Material Design Icons designed by the community for Flutter material_design_icons_flutter: ^7.0.7296 # Creating multi-select widgets in a variety of ways + mqtt_client: ^10.0.0 multi_select_flutter: ^4.1.3 # Service discovery over multicast DNS (mDNS), Bonjour, and Avahi. multicast_dns: ^0.3.2+4 @@ -143,7 +144,7 @@ dependencies: # Provides runtime support for a Dart implementation of protobufs. protobuf: ^3.1.0 # A wrapper around InheritedWidget to make them easier to use and more reusable. - provider: ^6.1.0 + provider: ^6.1.1 # Implementation of the popular reactiveX api for asynchronous programming rxdart: ^0.27.7 # Reading and writing simple key-value pairs @@ -151,6 +152,7 @@ dependencies: # Highly customizable circular slider/progress bar & spinner. sleek_circular_slider: ^2.0.1 # Plugin for launching a URL + timezone: ^0.9.2 url_launcher: ^6.2.1 # Simple, fast generation of RFC4122 UUIDs. uuid: ^4.2.1 From 7ae855726b55c01041ac8b88c9062ebb46158288 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 00:55:18 +0200 Subject: [PATCH 10/15] Removed unused files --- .../add_user_to_home_bloc.dart | 52 ----- .../add_user_to_home_event.dart | 12 -- .../add_user_to_home_state.dart | 23 --- lib/application/auth/auth_bloc.dart | 43 ---- lib/application/auth/auth_event.dart | 8 - lib/application/auth/auth_state.dart | 10 - .../auth/sign_in_form/sign_in_form_bloc.dart | 116 ----------- .../auth/sign_in_form/sign_in_form_event.dart | 18 -- .../auth/sign_in_form/sign_in_form_state.dart | 20 -- .../create_home/create_home_bloc.dart | 51 ----- .../create_home/create_home_event.dart | 11 - .../create_home/create_home_state.dart | 18 -- .../user_homes_list/user_homes_list_bloc.dart | 78 ------- .../user_homes_list_event.dart | 15 -- .../user_homes_list_state.dart | 24 --- lib/presentation/core/app_widget.dart | 105 +++++----- .../add_user_to_home_page.dart | 24 --- .../widgets/add_user_to_home_widget.dart | 192 ------------------ .../pages/create_home/create_home_page.dart | 37 ---- .../widgets/create_home_widget.dart | 143 ------------- .../blinds/rooms_blinds_page.dart | 11 - .../boilers/rooms_boilers_page.dart | 11 - .../lights/rooms_lights_page.dart | 11 - .../printers/rooms_printers_page.dart | 11 - .../rooms_smart_computers_page.dart | 11 - .../smart_plugs/rooms_smart_plugs_page.dart | 11 - .../smart_tv/rooms_smart_tvs_page.dart | 11 - .../switches/rooms_switches_page.dart | 11 - .../smart_devices_widgets.dart | 12 -- .../pages/manage_users/manage_users_page.dart | 87 -------- .../widgets/error_user_card_widget.dart | 42 ---- .../widgets/manage_users_widget.dart | 57 ------ .../widgets/user_card_widget.dart | 50 ----- .../pages/remote_pipes/remote_pipes_page.dart | 14 +- lib/presentation/pages/routes/app_router.dart | 2 - .../software_info/software_info_page.dart | 60 ++---- 36 files changed, 82 insertions(+), 1330 deletions(-) delete mode 100644 lib/application/add_user_to_home/add_user_to_home_bloc.dart delete mode 100644 lib/application/add_user_to_home/add_user_to_home_event.dart delete mode 100644 lib/application/add_user_to_home/add_user_to_home_state.dart delete mode 100644 lib/application/auth/auth_bloc.dart delete mode 100644 lib/application/auth/auth_event.dart delete mode 100644 lib/application/auth/auth_state.dart delete mode 100644 lib/application/auth/sign_in_form/sign_in_form_bloc.dart delete mode 100644 lib/application/auth/sign_in_form/sign_in_form_event.dart delete mode 100644 lib/application/auth/sign_in_form/sign_in_form_state.dart delete mode 100644 lib/application/create_home/create_home_bloc.dart delete mode 100644 lib/application/create_home/create_home_event.dart delete mode 100644 lib/application/create_home/create_home_state.dart delete mode 100644 lib/application/user_homes_list/user_homes_list_bloc.dart delete mode 100644 lib/application/user_homes_list/user_homes_list_event.dart delete mode 100644 lib/application/user_homes_list/user_homes_list_state.dart delete mode 100644 lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart delete mode 100644 lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart delete mode 100644 lib/presentation/pages/create_home/create_home_page.dart delete mode 100644 lib/presentation/pages/create_home/widgets/create_home_widget.dart delete mode 100644 lib/presentation/pages/manage_users/manage_users_page.dart delete mode 100644 lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart delete mode 100644 lib/presentation/pages/manage_users/widgets/manage_users_widget.dart delete mode 100644 lib/presentation/pages/manage_users/widgets/user_card_widget.dart diff --git a/lib/application/add_user_to_home/add_user_to_home_bloc.dart b/lib/application/add_user_to_home/add_user_to_home_bloc.dart deleted file mode 100644 index dea5fb46f..000000000 --- a/lib/application/add_user_to_home/add_user_to_home_bloc.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_value_objects.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/i_add_user_to_home_repository.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_value_objects.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'add_user_to_home_bloc.freezed.dart'; -part 'add_user_to_home_event.dart'; -part 'add_user_to_home_state.dart'; - -@injectable -class AddUserToHomeBloc extends Bloc { - AddUserToHomeBloc() : super(AddUserToHomeState.initial()) { - on(_emailChanged); - on(_permissionChanged); - on(_addUserToHomeByEmail); - } - - Future _emailChanged( - EmailChanged event, - Emitter emit, - ) async {} - - Future _permissionChanged( - PermissionChanged event, - Emitter emit, - ) async {} - - Future _addUserToHomeByEmail( - AddUserToHomeByEmail event, - Emitter emit, - ) async { - emit(const AddUserToHomeState.actionInProgress()); - - final HomeUserEntity addUserHomeEntity = HomeUserEntity.empty().copyWith( - email: HomeUserEmail(event.email), - permission: HomeUserPermission('Admin'), - ); - final userOption = - await IAddUserToHomeRepository.instance.add(addUserHomeEntity); - emit( - userOption.fold( - (_) => const AddUserToHomeState.addingHomeFailure(), - (homeID) => AddUserToHomeState.addingUserSuccess(homeID), - ), - ); - } -} diff --git a/lib/application/add_user_to_home/add_user_to_home_event.dart b/lib/application/add_user_to_home/add_user_to_home_event.dart deleted file mode 100644 index 15b4ff6ae..000000000 --- a/lib/application/add_user_to_home/add_user_to_home_event.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'add_user_to_home_bloc.dart'; - -@freezed -class AddUserToHomeEvent with _$AddUserToHomeEvent { - const factory AddUserToHomeEvent.emailChanged(String emailStr) = EmailChanged; - - const factory AddUserToHomeEvent.permissionChanged(String permission) = - PermissionChanged; - - const factory AddUserToHomeEvent.addUserToHomeByEmail(String email) = - AddUserToHomeByEmail; -} diff --git a/lib/application/add_user_to_home/add_user_to_home_state.dart b/lib/application/add_user_to_home/add_user_to_home_state.dart deleted file mode 100644 index 01f90fa40..000000000 --- a/lib/application/add_user_to_home/add_user_to_home_state.dart +++ /dev/null @@ -1,23 +0,0 @@ -part of 'add_user_to_home_bloc.dart'; - -@freezed -class AddUserToHomeState with _$AddUserToHomeState { - const factory AddUserToHomeState({ - required AddUserToHomeEmail emailAddress, - required AddUserToHomePermission permission, - required Option> - addUserFailureOrSuccessOption, - }) = _AddUserToHomeState; - - factory AddUserToHomeState.initial() => AddUserToHomeState( - emailAddress: AddUserToHomeEmail(''), - permission: AddUserToHomePermission(''), - addUserFailureOrSuccessOption: none(), - ); - - const factory AddUserToHomeState.actionInProgress() = _ActionInProgress; - - const factory AddUserToHomeState.addingUserSuccess(String homeId) = - AddingUserSucess; - const factory AddUserToHomeState.addingHomeFailure() = AddingHomeFauliare; -} diff --git a/lib/application/auth/auth_bloc.dart b/lib/application/auth/auth_bloc.dart deleted file mode 100644 index 319a786c7..000000000 --- a/lib/application/auth/auth_bloc.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'auth_bloc.freezed.dart'; -part 'auth_event.dart'; -part 'auth_state.dart'; - -@injectable -class AuthBloc extends Bloc { - AuthBloc() : super(const AuthState.initial()) { - on(_initialized); - on(_authCheckRequested); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const AuthState.initial()); - add(const AuthEvent.authCheckRequested()); - } - - Future _authCheckRequested( - AuthCheckRequested event, - Emitter emit, - ) async { - // For now will check only if hub connection info is saved - emit( - (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( - (l) => const AuthState.unauthenticated(), - (r) => const AuthState.authenticated(), - ), - ); - // - // final userOption = await _authFacade.getSignedInUser(); - // yield userOption.fold( - // () => const AuthState.unauthenticated(), - // (_) => const AuthState.authenticated(), - // ); - } -} diff --git a/lib/application/auth/auth_event.dart b/lib/application/auth/auth_event.dart deleted file mode 100644 index 80b8398e2..000000000 --- a/lib/application/auth/auth_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'auth_bloc.dart'; - -@freezed -class AuthEvent with _$AuthEvent { - const factory AuthEvent.initialized() = Initialized; - - const factory AuthEvent.authCheckRequested() = AuthCheckRequested; -} diff --git a/lib/application/auth/auth_state.dart b/lib/application/auth/auth_state.dart deleted file mode 100644 index d18a0c4f7..000000000 --- a/lib/application/auth/auth_state.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'auth_bloc.dart'; - -@freezed -class AuthState with _$AuthState { - const factory AuthState.initial() = Initial; - - const factory AuthState.authenticated() = Authenticated; - - const factory AuthState.unauthenticated() = Unauthenticated; -} diff --git a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart b/lib/application/auth/sign_in_form/sign_in_form_bloc.dart deleted file mode 100644 index 36096057e..000000000 --- a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart +++ /dev/null @@ -1,116 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; -import 'package:cybear_jinni/domain/auth/value_objects.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'sign_in_form_bloc.freezed.dart'; -part 'sign_in_form_event.dart'; -part 'sign_in_form_state.dart'; - -@injectable -class SignInFormBloc extends Bloc { - SignInFormBloc() : super(SignInFormState.initial()) { - on(_emailChanged); - on(_passwordChanged); - on(_registerWithEmailAndPassword); - on(_signInWithEmailAndPasswordPassed); - on(_signInWithGooglePressed); - } - - Future _emailChanged( - EmailChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - emailAddress: EmailAddress(event.emailStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _passwordChanged( - PasswordChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - password: Password(event.passwordStr), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _registerWithEmailAndPassword( - RegisterWithEmailAndPassword event, - Emitter emit, - ) async { - _performActionOnAuthFacadeWithEmailAndPassword( - IAuthFacade.instance.registerWithEmailAndPassword, - ).forEach((element) { - emit(element); - }); - } - - Future _signInWithEmailAndPasswordPassed( - SignInWithEmailAndPasswordPassed event, - Emitter emit, - ) async { - _performActionOnAuthFacadeWithEmailAndPassword( - IAuthFacade.instance.signInWithEmailAndPassword, - ).forEach((element) { - emit(element); - }); - } - - Future _signInWithGooglePressed( - SignInWithGooglePressed event, - Emitter emit, - ) async { - emit( - state.copyWith( - isSubmitting: true, - authFailureOrSuccessOption: none(), - ), - ); - emit( - state.copyWith( - isSubmitting: false, - authFailureOrSuccessOption: Some(right(unit)), - ), - ); - } - - Stream _performActionOnAuthFacadeWithEmailAndPassword( - Future> Function({ - required EmailAddress emailAddress, - required Password password, - }) forwardedCall, - ) async* { - Either? failureOrSuccess; - - final isEmailValid = state.emailAddress.isValid(); - final isPasswordValid = state.password.isValid(); - if (isEmailValid && isPasswordValid) { - yield state.copyWith( - isSubmitting: true, - authFailureOrSuccessOption: none(), - ); - - failureOrSuccess = await forwardedCall( - emailAddress: state.emailAddress, - password: state.password, - ); - } - yield state.copyWith( - isSubmitting: false, - showErrorMessages: true, - authFailureOrSuccessOption: optionOf(failureOrSuccess), - ); - } -} diff --git a/lib/application/auth/sign_in_form/sign_in_form_event.dart b/lib/application/auth/sign_in_form/sign_in_form_event.dart deleted file mode 100644 index b662eb0d4..000000000 --- a/lib/application/auth/sign_in_form/sign_in_form_event.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'sign_in_form_bloc.dart'; - -@freezed -class SignInFormEvent with _$SignInFormEvent { - const factory SignInFormEvent.emailChanged(String emailStr) = EmailChanged; - - const factory SignInFormEvent.passwordChanged(String passwordStr) = - PasswordChanged; - - const factory SignInFormEvent.registerWithEmailAndPassword() = - RegisterWithEmailAndPassword; - - const factory SignInFormEvent.signInWithEmailAndPasswordPassed() = - SignInWithEmailAndPasswordPassed; - - const factory SignInFormEvent.signInWithGooglePressed() = - SignInWithGooglePressed; -} diff --git a/lib/application/auth/sign_in_form/sign_in_form_state.dart b/lib/application/auth/sign_in_form/sign_in_form_state.dart deleted file mode 100644 index 207e10237..000000000 --- a/lib/application/auth/sign_in_form/sign_in_form_state.dart +++ /dev/null @@ -1,20 +0,0 @@ -part of 'sign_in_form_bloc.dart'; - -@freezed -class SignInFormState with _$SignInFormState { - const factory SignInFormState({ - required EmailAddress emailAddress, - required Password password, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _SignInFormState; - - factory SignInFormState.initial() => SignInFormState( - emailAddress: EmailAddress(''), - password: Password(''), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/create_home/create_home_bloc.dart b/lib/application/create_home/create_home_bloc.dart deleted file mode 100644 index 312c08d68..000000000 --- a/lib/application/create_home/create_home_bloc.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_entity.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_value_objects.dart'; -import 'package:cybear_jinni/domain/create_home/i_create_home_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'create_home_bloc.freezed.dart'; -part 'create_home_event.dart'; -part 'create_home_state.dart'; - -@injectable -class CreateHomeBloc extends Bloc { - CreateHomeBloc() : super(CreateHomeState.initialized()) { - on(_initialized); - on(_createHome); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _createHome( - CreateHome event, - Emitter emit, - ) async { - emit(const CreateHomeState.loading()); - final CreateHomeEntity createHomeEntity = CreateHomeEntity( - id: HomeUniqueId(), - name: HomeName(event.homeName), - homeDevicesUserId: HomeDevicesUserId(), - homeDevicesUserEmail: HomeDevicesUserEmail(event.devicesEmail), - homeDevicesUserPassword: HomeDevicesUserPassword(), - ); - - final initialization = - await ICreateHomeRepository.instance.createNewHome(createHomeEntity); - - emit( - initialization.fold( - (_) => const CreateHomeState.error(), - (_) => const CreateHomeState.loaded(), - ), - ); - } -} diff --git a/lib/application/create_home/create_home_event.dart b/lib/application/create_home/create_home_event.dart deleted file mode 100644 index 1f1a94631..000000000 --- a/lib/application/create_home/create_home_event.dart +++ /dev/null @@ -1,11 +0,0 @@ -part of 'create_home_bloc.dart'; - -@freezed -class CreateHomeEvent with _$CreateHomeEvent { - const factory CreateHomeEvent.initialized() = Initialized; - - const factory CreateHomeEvent.createHome( - String homeName, - String devicesEmail, - ) = CreateHome; -} diff --git a/lib/application/create_home/create_home_state.dart b/lib/application/create_home/create_home_state.dart deleted file mode 100644 index 6cf85b331..000000000 --- a/lib/application/create_home/create_home_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'create_home_bloc.dart'; - -@freezed -class CreateHomeState with _$CreateHomeState { - const factory CreateHomeState({ - required Option> authFailureOrSuccessOption, - }) = _CreateHomeState; - - factory CreateHomeState.initialized() => CreateHomeState( - authFailureOrSuccessOption: none(), - ); - - const factory CreateHomeState.loading() = Loading; - - const factory CreateHomeState.loaded() = Loaded; - - const factory CreateHomeState.error() = Error; -} diff --git a/lib/application/user_homes_list/user_homes_list_bloc.dart b/lib/application/user_homes_list/user_homes_list_bloc.dart deleted file mode 100644 index 198c66dd7..000000000 --- a/lib/application/user_homes_list/user_homes_list_bloc.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_failures.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'user_homes_list_bloc.freezed.dart'; -part 'user_homes_list_event.dart'; -part 'user_homes_list_state.dart'; - -@injectable -class UserHomesListBloc extends Bloc { - UserHomesListBloc() : super(UserHomesListState.initial()) { - on(_watchAllStarted); - on(_allHomesOfUserReceived); - on(_joinExistingHome); - } - - StreamSubscription< - Either>>? - _userHomesStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const UserHomesListState.loadInProgress()); - await _userHomesStreamSubscription?.cancel(); - _userHomesStreamSubscription = IUserRepository.instance.watchAll().listen( - (failureOrDevices) => add( - UserHomesListEvent.allHomesOfUserReceived(failureOrDevices), - ), - ); - } - - Future _allHomesOfUserReceived( - AllHomesOfUserReceived event, - Emitter emit, - ) async { - emit(const UserHomesListState.loadInProgress()); - - emit( - event.failureOrAllHomesOfUser.fold( - (f) => UserHomesListState.loadFailure(f), - (allHomes) => UserHomesListState.loadSuccess(allHomes), - ), - ); - } - - Future _joinExistingHome( - JoinExistingHome event, - Emitter emit, - ) async { - emit(const UserHomesListState.loadInProgress()); - - final Either joinHomeOutput = await IUserRepository - .instance - .joinExistingHome(event.allHomesOfUserEntity!); - emit( - joinHomeOutput.fold( - (f) => UserHomesListState.loadFailureEnteringHome(f), - (r) => const UserHomesListState.enterHome(), - ), - ); - } - - @override - Future close() async { - await _userHomesStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/user_homes_list/user_homes_list_event.dart b/lib/application/user_homes_list/user_homes_list_event.dart deleted file mode 100644 index b8c8bb73f..000000000 --- a/lib/application/user_homes_list/user_homes_list_event.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'user_homes_list_bloc.dart'; - -@freezed -class UserHomesListEvent with _$UserHomesListEvent { - const factory UserHomesListEvent.watchAllStarted() = WatchAllStarted; - - const factory UserHomesListEvent.joinExistingHome( - AllHomesOfUserEntity? allHomesOfUserEntity, - ) = JoinExistingHome; - - const factory UserHomesListEvent.allHomesOfUserReceived( - Either> - failureOrAllHomesOfUser, - ) = AllHomesOfUserReceived; -} diff --git a/lib/application/user_homes_list/user_homes_list_state.dart b/lib/application/user_homes_list/user_homes_list_state.dart deleted file mode 100644 index 9feee8bde..000000000 --- a/lib/application/user_homes_list/user_homes_list_state.dart +++ /dev/null @@ -1,24 +0,0 @@ -part of 'user_homes_list_bloc.dart'; - -@freezed -class UserHomesListState with _$UserHomesListState { - factory UserHomesListState.initial() = _Initial; - - const factory UserHomesListState.loadInProgress() = _LoadInProgress; - - const factory UserHomesListState.loadSuccess( - KtList homes, - ) = _LoadSuccess; - - const factory UserHomesListState.enterHome() = _EnterHome; - - const factory UserHomesListState.loadFailure( - AllHomesOfUserFailures allHomesOfUserFailures, - ) = _LoadFailure; - - const factory UserHomesListState.loadFailureEnteringHome( - HomeUserFailures allHomesOfUserFailures, - ) = _LoadFailureEnteringHome; - - const factory UserHomesListState.error() = Error; -} diff --git a/lib/presentation/core/app_widget.dart b/lib/presentation/core/app_widget.dart index 9640fde10..3440bb67b 100644 --- a/lib/presentation/core/app_widget.dart +++ b/lib/presentation/core/app_widget.dart @@ -1,12 +1,33 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; +import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.dart'; +import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -class AppWidget extends StatelessWidget { +class AppWidget extends StatefulWidget { + @override + State createState() => _AppWidgetState(); +} + +class _AppWidgetState extends State { + @override + void initState() { + super.initState(); + } + + Future initialize() async { + (await ILocalDbRepository2.instance.getHubEntityNetworkName()).fold( + (l) { + context.router.replace(const ConnectToHubRoute()); + }, + (r) { + context.router.replace(const HomeRoute()); + }, + ); + } + MaterialColor createMaterialColor(Color color) { final List strengths = [.05]; final Map swatch = {}; @@ -33,52 +54,44 @@ class AppWidget extends StatelessWidget { Widget build(BuildContext context) { final rootRouter = getIt(); - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => - getIt()..add(const AuthEvent.initialized()), + return MaterialApp.router( + routerConfig: rootRouter.config( + navigatorObservers: () => [AutoRouteObserver()], + ), + // routeInformationParser: rootRouter.defaultRouteParser(), + title: 'CyBear Jinni App', + // builder: ExtendedNavigator( + // router: AppRouter(), + // ), + // initialRoute: + // auth.currentU1`ser != null ? '/$homePage' : '/$loginPage', + localizationsDelegates: context.localizationDelegates, + supportedLocales: context.supportedLocales, + locale: context.locale, + // darkTheme: ThemeData(brightness: Brightness.dark), + debugShowCheckedModeBanner: false, + theme: ThemeData( + useMaterial3: true, + primaryColor: + createMaterialColor(const Color.fromRGBO(162, 129, 162, 1.0)), + primaryColorDark: const Color(0xFF271052), + inputDecorationTheme: InputDecorationTheme( + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), ), - ], - child: MaterialApp.router( - routerConfig: rootRouter.config( - navigatorObservers: () => [AutoRouteObserver()], + textTheme: const TextTheme( + bodyLarge: TextStyle(color: Colors.white), + bodyMedium: TextStyle(color: Colors.white70), ), - // routeInformationParser: rootRouter.defaultRouteParser(), - title: 'CyBear Jinni App', - // builder: ExtendedNavigator( - // router: AppRouter(), - // ), - // initialRoute: - // auth.currentU1`ser != null ? '/$homePage' : '/$loginPage', - localizationsDelegates: context.localizationDelegates, - supportedLocales: context.supportedLocales, - locale: context.locale, - // darkTheme: ThemeData(brightness: Brightness.dark), - debugShowCheckedModeBanner: false, - theme: ThemeData( - useMaterial3: true, - primaryColor: - createMaterialColor(const Color.fromRGBO(162, 129, 162, 1.0)), - primaryColorDark: const Color(0xFF271052), - inputDecorationTheme: InputDecorationTheme( - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - textTheme: const TextTheme( - bodyLarge: TextStyle(color: Colors.white), - bodyMedium: TextStyle(color: Colors.white70), - ), - fontFamily: 'gidole_regular', - colorScheme: ColorScheme.fromSwatch( - primarySwatch: createMaterialColor( - const Color.fromRGBO(162, 129, 162, 1.0), - ), - accentColor: Colors.yellow, - ).copyWith( - secondary: Colors.indigo, + fontFamily: 'gidole_regular', + colorScheme: ColorScheme.fromSwatch( + primarySwatch: createMaterialColor( + const Color.fromRGBO(162, 129, 162, 1.0), ), + accentColor: Colors.yellow, + ).copyWith( + secondary: Colors.indigo, ), ), ); diff --git a/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart b/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart deleted file mode 100644 index ce08fc520..000000000 --- a/lib/presentation/pages/add_user_to_home/add_user_to_home_page.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_user_to_home/add_user_to_home_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class AddUserToHomePage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const TextAtom('Add user'), - ), - backgroundColor: Colors.blueAccent.withOpacity(0.7), - body: BlocProvider( - create: (context) => getIt(), - child: AddUserToHomeWidget(), - ), - ); - } -} diff --git a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart b/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart deleted file mode 100644 index 1ef567f24..000000000 --- a/lib/presentation/pages/add_user_to_home/widgets/add_user_to_home_widget.dart +++ /dev/null @@ -1,192 +0,0 @@ -import 'package:clipboard/clipboard.dart'; -import 'package:cybear_jinni/application/add_user_to_home/add_user_to_home_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:fluttertoast/fluttertoast.dart'; - -class AddUserToHomeWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - String userToAddEmail = ''; - - return BlocConsumer( - listener: (context, state) { - state.map( - (value) => const TextAtom('Initial'), - actionInProgress: (_) { - return const CircularProgressIndicatorAtom(); - }, - addingUserSuccess: (s) { - return TextButton( - onPressed: () {}, - child: const TextAtom('Success'), - ); - }, - addingHomeFailure: (e) { - return const TextAtom('Failure'); - }, - ); - }, - builder: (context, state) { - return Column( - children: [ - const SizedBox( - height: 30, - ), - Row( - children: [ - const SizedBox( - width: 10, - ), - const TextAtom('Email'), - const SizedBox( - width: 30, - ), - SizedBox( - width: 300, - child: TextFormField( - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.alternate_email, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'Email', - labelStyle: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - userToAddEmail = value; - }, - ), - ), - ], - ), - const SizedBox( - height: 30, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.pinkAccent, - ), - ), - onPressed: () { - context.read().add( - AddUserToHomeEvent.addUserToHomeByEmail(userToAddEmail), - ); - }, - child: TextAtom( - 'Add User', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - state.map( - (value) => const SizedBox(), - actionInProgress: (_) { - return const CircularProgressIndicatorAtom(); - }, - addingUserSuccess: (s) { - return Container( - margin: const EdgeInsets.symmetric(horizontal: 30), - child: Column( - children: [ - const SizedBox( - height: 30, - ), - TextAtom( - 'User have been add successfully', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 20, - ), - ), - const SizedBox( - height: 30, - ), - const SizedBox( - height: 30, - ), - TextAtom( - 'Copy home ID', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 20, - ), - ), - const SizedBox( - height: 30, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.green, - ), - ), - onPressed: () { - FlutterClipboard.copy(s.homeId).then( - (value) => Fluttertoast.showToast( - msg: 'Copy', - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.SNACKBAR, - backgroundColor: Colors.lightBlue, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ), - ); - }, - child: Column( - children: [ - const TextAtom('Press to copy'), - TextAtom( - s.homeId, - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontWeight: FontWeight.bold, - fontSize: 20, - ), - ), - ], - ), - ), - TextAtom( - 'Please give home id to the user, he needs it to' - ' join the home.', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 15, - ), - ), - ], - ), - ); - }, - addingHomeFailure: (e) { - return TextAtom( - 'Adding user Failed.\n' - 'Did the user already created account with that email?', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ); - }, - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/create_home/create_home_page.dart b/lib/presentation/pages/create_home/create_home_page.dart deleted file mode 100644 index a513415bf..000000000 --- a/lib/presentation/pages/create_home/create_home_page.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/create_home/create_home_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/create_home/widgets/create_home_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -/// Loading page when initializing new home -@RoutePage() -class CreateHomePage extends StatelessWidget { - void backButtonFunction(BuildContext context) { - Navigator.pop(context); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const TextAtom('Home Information'), - ), - backgroundColor: Colors.blueAccent.withOpacity(0.7), - body: Column( - children: [ - const SizedBox( - height: 30, - ), - BlocProvider( - create: (context) => getIt() - ..add(const CreateHomeEvent.initialized()), - child: CreateHomeWidget(), - ), - ], - ), - ); - } -} diff --git a/lib/presentation/pages/create_home/widgets/create_home_widget.dart b/lib/presentation/pages/create_home/widgets/create_home_widget.dart deleted file mode 100644 index fdda9a20a..000000000 --- a/lib/presentation/pages/create_home/widgets/create_home_widget.dart +++ /dev/null @@ -1,143 +0,0 @@ -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/create_home/create_home_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class CreateHomeWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - String? homeName; - String? devicesEmail; - - return Column( - children: [ - Container( - color: Colors.black54, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), - child: const TextAtom( - 'Name for your home', - style: TextStyle(fontSize: 20), - ), - ), - const SizedBox( - height: 20, - ), - SizedBox( - width: 300, - child: TextFormField( - style: - TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.home_outlined, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'Home Name', - labelStyle: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - homeName = value; - }, - ), - ), - const SizedBox( - height: 50, - ), - Container( - color: Colors.black54, - padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), - child: const TextAtom( - 'Email for the Smart Devices', - style: TextStyle(fontSize: 20), - ), - ), - const SizedBox( - height: 20, - ), - SizedBox( - width: 300, - child: TextFormField( - style: - TextStyle(color: Theme.of(context).textTheme.bodyLarge!.color), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.alternate_email, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'Email for smart devices', - labelStyle: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - devicesEmail = value; - }, - ), - ), - const SizedBox( - height: 5, - ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 48), - child: TextAtom( - 'Smart devices needs account to function.\nPlease enter new email.', - style: TextStyle( - fontSize: 15, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - const SizedBox( - height: 20, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.pinkAccent), - ), - onPressed: () { - context - .read() - .add(CreateHomeEvent.createHome(homeName!, devicesEmail!)); - }, - child: TextAtom( - 'Create Home', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - BlocBuilder( - builder: (context, state) { - return state.map( - (value) { - return const TextAtom(''); - }, - loading: (loadingNow) { - return const CircularProgressIndicatorAtom(); - }, - error: (errorNow) { - FlushbarHelper.createError(message: 'Error'); - return const TextAtom('Error'); - }, - loaded: (_) { - context.router.replace(const HomeRoute()); - return const TextAtom('Loaded'); - }, - ); - }, - ), - ], - ); - } -} diff --git a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart index ad44032c0..4b8e5abd8 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/blinds/blinds_watcher/blinds_watcher_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -57,15 +55,6 @@ class RoomsBlindsPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart index b2c98f6e3..89bd84ccd 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -57,15 +55,6 @@ class RoomsBoilersPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubMoreRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart index a48847e3e..c9f80d04d 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -55,15 +53,6 @@ class RoomsLightsPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart index b5e09ab97..14d26eb3a 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -58,15 +56,6 @@ class RoomsPrintersPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart index f7f3cefe2..4cc20c40f 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -58,15 +56,6 @@ class RoomsSmartComputersPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart index 385479169..01a39ea74 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -58,15 +56,6 @@ class RoomsSmartPlugsPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart index 509da8f0a..1f2b6b86c 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -58,15 +56,6 @@ class RoomsSmartTvsPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart index 7f0c99b5a..b51b25735 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/switches/switches_watcher/switches_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; @@ -9,7 +8,6 @@ import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -58,15 +56,6 @@ class RoomsSwitchesPage extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart index 3339e0efd..84c3a3524 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart @@ -1,14 +1,11 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -69,15 +66,6 @@ class SmartDevicesWidgets extends StatelessWidget { ], child: MultiBlocListener( listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), BlocListener( listener: (context, state) { state.maybeMap( diff --git a/lib/presentation/pages/manage_users/manage_users_page.dart b/lib/presentation/pages/manage_users/manage_users_page.dart deleted file mode 100644 index d7a34a3a0..000000000 --- a/lib/presentation/pages/manage_users/manage_users_page.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; -import 'package:cybear_jinni/application/manage_users/manage_users_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/manage_users/widgets/manage_users_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -@RoutePage() -class ManageUsersPage extends StatelessWidget { - /// Execute when user press the icon in top right side - void userCogFunction(BuildContext context) { - showAdaptiveActionSheet( - context: context, - actions: [ - BottomSheetAction( - title: const TextAtom( - '➕ Add User', - style: TextStyle(color: Colors.green, fontSize: 23), - ), - onPressed: (_) { - context.router.push(const AddUserToHomeRoute()); - }, - ), - ], - ); - } - - void leftIconFunction(BuildContext context) { - Navigator.pop(context); - } - - @override - Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const ManageUsersEvent.initialized()), - ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: ColoredBox( - color: Colors.black87, - child: Column( - children: [ - TopNavigationBar( - pageName: 'Users', - rightIcon: Icons.more_vert, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, - ), - Expanded( - child: ManageUsersWidget(), - ), - ], - ), - ), - ), - ), - ); - } -} diff --git a/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart b/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart deleted file mode 100644 index 295b17b81..000000000 --- a/lib/presentation/pages/manage_users/widgets/error_user_card_widget.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:flutter/material.dart'; - -class ErrorUserCard extends StatelessWidget { - const ErrorUserCard({ - required this.homeUser, - super.key, - }); - - final HomeUserEntity? homeUser; - - @override - Widget build(BuildContext context) { - return Card( - color: Theme.of(context).colorScheme.error, - child: Padding( - padding: const EdgeInsets.all(4), - child: Column( - children: [ - TextAtom( - 'Invalid user, please, contact support', - style: Theme.of(context) - .primaryTextTheme - .bodyMedium! - .copyWith(fontSize: 18), - ), - const SizedBox(height: 2), - TextAtom( - 'Details for nerds:', - style: Theme.of(context).primaryTextTheme.bodyMedium, - ), - TextAtom( - homeUser!.failureOption.fold(() => '', (f) => f.toString()), - style: Theme.of(context).primaryTextTheme.bodyMedium, - ), - ], - ), - ), - ); - } -} diff --git a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart b/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart deleted file mode 100644 index dbb6cfd9e..000000000 --- a/lib/presentation/pages/manage_users/widgets/manage_users_widget.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:cybear_jinni/application/manage_users/manage_users_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/manage_users/widgets/error_user_card_widget.dart'; -import 'package:cybear_jinni/presentation/pages/manage_users/widgets/user_card_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -/// Show light toggles in a container with the background color from smart room -/// object -class ManageUsersWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => Container(), - inProgress: (state) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 100), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final homeUser = state.homeUsers[index]; - if (homeUser.failureOption.isSome()) { - return ErrorUserCard(homeUser: homeUser); - } else { - return UserCard(homeUser: homeUser); - } - }, - itemCount: state.homeUsers.size, - ), - ); - }, - loadFailure: (state) { - return const TextAtom('Load Failure'); - }, - addSuccess: (state) { - return const TextAtom('Add Success'); - }, - deleteFailure: (state) { - return const TextAtom('Delete Failure'); - }, - deleteSuccess: (state) { - return const TextAtom('Delete Success'); - }, - error: (state) { - return const TextAtom('Error'); - }, - ); - }, - ); - } -} diff --git a/lib/presentation/pages/manage_users/widgets/user_card_widget.dart b/lib/presentation/pages/manage_users/widgets/user_card_widget.dart deleted file mode 100644 index e4d1b3ace..000000000 --- a/lib/presentation/pages/manage_users/widgets/user_card_widget.dart +++ /dev/null @@ -1,50 +0,0 @@ -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class UserCard extends StatelessWidget { - const UserCard({ - required this.homeUser, - super.key, - }); - - final HomeUserEntity? homeUser; - - @override - Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - bottom: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - ), - ), - height: 100, - child: Center( - child: ListTile( - leading: FaIcon( - FontAwesomeIcons.userGraduate, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - TextAtom( - homeUser!.email!.getOrCrash()!, - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - onTap: () {}, - ), - ), - ); - } -} diff --git a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart index 775cdc622..47e5f25ea 100644 --- a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart +++ b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart @@ -1,11 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/application/remote_pipes/remote_pipes_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -45,17 +43,7 @@ class RemotePipesPage extends StatelessWidget { ), ], child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), - ], + listeners: [], child: Scaffold( appBar: AppBar( toolbarHeight: 0, diff --git a/lib/presentation/pages/routes/app_router.dart b/lib/presentation/pages/routes/app_router.dart index 7f7c60dff..75f67239b 100644 --- a/lib/presentation/pages/routes/app_router.dart +++ b/lib/presentation/pages/routes/app_router.dart @@ -9,7 +9,6 @@ class AppRouter extends $AppRouter { AutoRoute(page: IntroductionRouteRoute.page), AutoRoute(page: ConnectToHubRoute.page), AutoRoute(page: ConnectToHubMoreRoute.page), - AutoRoute(page: CreateHomeRoute.page), AutoRoute(page: ChooseDeviceVendorToAddRoute.page), AutoRoute(page: JoinHomeByIdRoute.page), AutoRoute(page: HomeRoute.page), @@ -19,7 +18,6 @@ class AppRouter extends $AppRouter { AutoRoute(page: RemotePipesRoute.page), AutoRoute(page: SoftwareInfoRoute.page), AutoRoute(page: ManageUsersRoute.page), - AutoRoute(page: AddUserToHomeRoute.page), AutoRoute(page: ScenesRoute.page), AutoRoute(page: AddSceneRoute.page), AutoRoute(page: AddRoutineRoute.page), diff --git a/lib/presentation/pages/software_info/software_info_page.dart b/lib/presentation/pages/software_info/software_info_page.dart index cae0fa4a9..257304168 100644 --- a/lib/presentation/pages/software_info/software_info_page.dart +++ b/lib/presentation/pages/software_info/software_info_page.dart @@ -1,13 +1,10 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/auth/auth_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:cybear_jinni/presentation/pages/software_info/widgets/software_info_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -36,42 +33,29 @@ class SoftwareInfoPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - unauthenticated: (_) => - context.router.replace(const ConnectToHubRoute()), - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: const SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.light, - ), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: const SystemUiOverlayStyle( + statusBarIconBrightness: Brightness.light, ), - body: ColoredBox( - color: Colors.black87, - child: Column( - children: [ - TopNavigationBar( - pageName: 'Software Info', - rightIcon: null, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, - ), - Expanded( - child: SoftwareInfoWidget(), - ), - ], - ), + ), + body: ColoredBox( + color: Colors.black87, + child: Column( + children: [ + TopNavigationBar( + pageName: 'Software Info', + rightIcon: null, + rightIconFunction: userCogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: leftIconFunction, + ), + Expanded( + child: SoftwareInfoWidget(), + ), + ], ), ), ); From 71e18e4237184d73f383d6335492863467305db0 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 12:08:21 +0200 Subject: [PATCH 11/15] Converting more files to atoms widget architecture from bloc --- .../add_new_action/add_new_action_bloc.dart | 125 ------ .../add_new_action/add_new_action_event.dart | 17 - .../add_new_action/add_new_action_state.dart | 30 -- .../add_new_binding/add_new_binding_bloc.dart | 124 ------ .../add_new_binding_event.dart | 22 - .../add_new_binding_state.dart | 19 - .../add_new_routine/add_new_routine_bloc.dart | 149 ------- .../add_new_routine_event.dart | 28 -- .../add_new_routine_state.dart | 22 - .../add_new_scene/add_new_scene_bloc.dart | 127 ------ .../add_new_scene/add_new_scene_event.dart | 21 - .../add_new_scene/add_new_scene_state.dart | 19 - .../folder_of_bindings_bloc.dart | 56 --- .../folder_of_bindings_event.dart | 8 - .../folder_of_bindings_state.dart | 24 - .../folder_of_routines_bloc.dart | 56 --- .../folder_of_routines_event.dart | 8 - .../folder_of_routines_state.dart | 24 - .../folder_of_scenes_bloc.dart | 55 --- .../folder_of_scenes_event.dart | 8 - .../folder_of_scenes_state.dart | 24 - .../folders_of_bindings_bloc.dart | 62 --- .../folders_of_bindings_event.dart | 6 - .../folders_of_bindings_state.dart | 22 - .../folders_of_routines_bloc.dart | 62 --- .../folders_of_routines_event.dart | 6 - .../folders_of_routines_state.dart | 22 - .../folders_of_scenes_bloc.dart | 62 --- .../folders_of_scenes_event.dart | 6 - .../folders_of_scenes_state.dart | 22 - .../join_home_by_id/join_home_by_id_bloc.dart | 60 --- .../join_home_by_id_event.dart | 8 - .../join_home_by_id_state.dart | 18 - .../manage_access_point_bloc.dart | 80 ---- .../manage_access_point_event.dart | 8 - .../manage_access_point_state.dart | 21 - .../manage_users/manage_users_bloc.dart | 67 --- .../manage_users/manage_users_event.dart | 15 - .../manage_users/manage_users_state.dart | 24 - .../more_connections_options_bloc.dart | 60 --- .../more_connections_options_event.dart | 13 - .../more_connections_options_state.dart | 14 - .../remote_pipes/remote_pipes_bloc.dart | 65 --- .../remote_pipes/remote_pipes_event.dart | 16 - .../remote_pipes/remote_pipes_state.dart | 12 - .../create_home/create_home_entity.dart | 15 - .../create_home/create_home_errors.dart | 14 - .../create_home/create_home_failure.dart | 24 - .../create_home/create_home_validators.dart | 21 - .../create_home_value_objects.dart | 109 ----- .../create_home/i_create_home_repository.dart | 28 -- .../i_remote_pipes_repository.dart | 16 - .../remote_pipes/remote_pipes_entity.dart | 32 -- .../remote_pipes/remote_pipes_errors.dart | 16 - .../remote_pipes/remote_pipes_failures.dart | 17 - .../remote_pipes/remote_pipes_validators.dart | 16 - .../remote_pipes_value_objects.dart | 50 --- .../create_home/create_home_dtos.dart | 56 --- .../create_home/create_home_repository.dart | 239 ---------- .../hub_client/hub_requests_routing.dart | 5 +- .../remote_pipes/remote_pipes_dtos.dart | 47 -- .../remote_pipes/remote_pipes_repository.dart | 38 -- .../add_action/add_action_page.dart | 8 +- .../widgets/action_choose_information.dart | 400 ++++++++++------- .../add_bindings/add_binding_page.dart | 8 +- .../widgets/add_binding_widget.dart | 353 ++++++++------- .../add_routine/add_routine_page.dart | 15 +- .../widgets/add_routine_widget.dart | 371 +++++++++------- .../add_scene/add_scene_page.dart | 8 +- .../add_scene/widgets/add_scene_widget.dart | 367 ++++++++------- .../open_access_pointi_page.dart | 9 +- .../widgets/open_access_point_widget.dart | 416 ++++++++++-------- .../widgets/cbj_hub_in_network_widget.dart | 1 + .../connect_to_hub_more_page.dart | 14 +- .../widgets/connect_to_hub_more_widget.dart | 249 ++++++----- .../add_bindings/add_bindings_page.dart | 89 ---- .../tabs/bindings_tab/bindings_page.dart | 138 ------ .../tabs/history_tab/history_tab.dart | 44 -- .../history_tab/settings_page_of_history.dart | 61 --- .../scenes_in_folders_tab.dart | 9 +- .../widgets/scenes_in_folders_l.dart | 117 +++-- .../join_home_by_id/join_home_by_id_page.dart | 24 - .../widgets/join_home_by_id_widget.dart | 129 ------ .../pages/remote_pipes/remote_pipes_page.dart | 49 +-- .../widgets/manage_remote_pipes_widget.dart | 138 +++--- lib/presentation/pages/routes/app_router.dart | 2 - .../pages/scenes/scenes_page.dart | 15 +- .../scenes/widgets/folder_of_scenes.dart | 127 +++--- .../pages/splash/splash_page.dart | 1 + 89 files changed, 1464 insertions(+), 4158 deletions(-) delete mode 100644 lib/application/add_new_action/add_new_action_bloc.dart delete mode 100644 lib/application/add_new_action/add_new_action_event.dart delete mode 100644 lib/application/add_new_action/add_new_action_state.dart delete mode 100644 lib/application/add_new_binding/add_new_binding_bloc.dart delete mode 100644 lib/application/add_new_binding/add_new_binding_event.dart delete mode 100644 lib/application/add_new_binding/add_new_binding_state.dart delete mode 100644 lib/application/add_new_routine/add_new_routine_bloc.dart delete mode 100644 lib/application/add_new_routine/add_new_routine_event.dart delete mode 100644 lib/application/add_new_routine/add_new_routine_state.dart delete mode 100644 lib/application/add_new_scene/add_new_scene_bloc.dart delete mode 100644 lib/application/add_new_scene/add_new_scene_event.dart delete mode 100644 lib/application/add_new_scene/add_new_scene_state.dart delete mode 100644 lib/application/folder_of_bindings/folder_of_bindings_bloc.dart delete mode 100644 lib/application/folder_of_bindings/folder_of_bindings_event.dart delete mode 100644 lib/application/folder_of_bindings/folder_of_bindings_state.dart delete mode 100644 lib/application/folder_of_routines/folder_of_routines_bloc.dart delete mode 100644 lib/application/folder_of_routines/folder_of_routines_event.dart delete mode 100644 lib/application/folder_of_routines/folder_of_routines_state.dart delete mode 100644 lib/application/folder_of_scenes/folder_of_scenes_bloc.dart delete mode 100644 lib/application/folder_of_scenes/folder_of_scenes_event.dart delete mode 100644 lib/application/folder_of_scenes/folder_of_scenes_state.dart delete mode 100644 lib/application/folders_of_bindings/folders_of_bindings_bloc.dart delete mode 100644 lib/application/folders_of_bindings/folders_of_bindings_event.dart delete mode 100644 lib/application/folders_of_bindings/folders_of_bindings_state.dart delete mode 100644 lib/application/folders_of_routines/folders_of_routines_bloc.dart delete mode 100644 lib/application/folders_of_routines/folders_of_routines_event.dart delete mode 100644 lib/application/folders_of_routines/folders_of_routines_state.dart delete mode 100644 lib/application/folders_of_scenes/folders_of_scenes_bloc.dart delete mode 100644 lib/application/folders_of_scenes/folders_of_scenes_event.dart delete mode 100644 lib/application/folders_of_scenes/folders_of_scenes_state.dart delete mode 100644 lib/application/join_home_by_id/join_home_by_id_bloc.dart delete mode 100644 lib/application/join_home_by_id/join_home_by_id_event.dart delete mode 100644 lib/application/join_home_by_id/join_home_by_id_state.dart delete mode 100644 lib/application/manage_access_point/manage_access_point_bloc.dart delete mode 100644 lib/application/manage_access_point/manage_access_point_event.dart delete mode 100644 lib/application/manage_access_point/manage_access_point_state.dart delete mode 100644 lib/application/manage_users/manage_users_bloc.dart delete mode 100644 lib/application/manage_users/manage_users_event.dart delete mode 100644 lib/application/manage_users/manage_users_state.dart delete mode 100644 lib/application/more_connections_options/more_connections_options_bloc.dart delete mode 100644 lib/application/more_connections_options/more_connections_options_event.dart delete mode 100644 lib/application/more_connections_options/more_connections_options_state.dart delete mode 100644 lib/application/remote_pipes/remote_pipes_bloc.dart delete mode 100644 lib/application/remote_pipes/remote_pipes_event.dart delete mode 100644 lib/application/remote_pipes/remote_pipes_state.dart delete mode 100644 lib/domain/create_home/create_home_entity.dart delete mode 100644 lib/domain/create_home/create_home_errors.dart delete mode 100644 lib/domain/create_home/create_home_failure.dart delete mode 100644 lib/domain/create_home/create_home_validators.dart delete mode 100644 lib/domain/create_home/create_home_value_objects.dart delete mode 100644 lib/domain/create_home/i_create_home_repository.dart delete mode 100644 lib/domain/remote_pipes/i_remote_pipes_repository.dart delete mode 100644 lib/domain/remote_pipes/remote_pipes_entity.dart delete mode 100644 lib/domain/remote_pipes/remote_pipes_errors.dart delete mode 100644 lib/domain/remote_pipes/remote_pipes_failures.dart delete mode 100644 lib/domain/remote_pipes/remote_pipes_validators.dart delete mode 100644 lib/domain/remote_pipes/remote_pipes_value_objects.dart delete mode 100644 lib/infrastructure/create_home/create_home_dtos.dart delete mode 100644 lib/infrastructure/create_home/create_home_repository.dart delete mode 100644 lib/infrastructure/remote_pipes/remote_pipes_dtos.dart delete mode 100644 lib/infrastructure/remote_pipes/remote_pipes_repository.dart delete mode 100644 lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart delete mode 100644 lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart delete mode 100644 lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart delete mode 100644 lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart delete mode 100644 lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart delete mode 100644 lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart diff --git a/lib/application/add_new_action/add_new_action_bloc.dart b/lib/application/add_new_action/add_new_action_bloc.dart deleted file mode 100644 index cde3dff53..000000000 --- a/lib/application/add_new_action/add_new_action_bloc.dart +++ /dev/null @@ -1,125 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'add_new_action_bloc.freezed.dart'; -part 'add_new_action_event.dart'; -part 'add_new_action_state.dart'; - -@injectable -class AddNewActionBloc extends Bloc { - AddNewActionBloc() : super(AddNewActionState.initial()) { - on(_changeActionDevices); - on(_actionsNameChange); - on(_changePropertyForDevices); - on(_initialized); - - add(const AddNewActionEvent.initialized()); - } - - List _allRooms = []; - List _allDevices = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - (await IRoomRepository.instance.getAllRooms()).fold((l) => null, (r) { - _allRooms = List.from(r.iter); - }); - - (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { - _allDevices = List.from(r.iter); - }); - _allRooms.removeWhere((element) => element == null); - _allDevices.removeWhere((element) => element == null); - - emit( - state.copyWith( - allDevices: _allDevices as List, - ), - ); - } - - Future _changeActionDevices( - ChangeActionDevices event, - Emitter emit, - ) async { - for (final DeviceEntityAbstract? device in _allDevices) { - if (device != null && - event.actionForProperty == device.uniqueId.getOrCrash()) { - emit( - state.copyWith( - allDevicesWithNewAction: [ - MapEntry(device, const MapEntry(null, null)), - ], - actionsName: '', - authFailureOrSuccessOption: none(), - ), - ); - } - } - } - - Future _actionsNameChange( - ActionsNameChange event, - Emitter emit, - ) async { - if (state.allDevicesWithNewAction.isNotEmpty) { - final List>> - tempAllDevicesWithNewActionList = - List.from(state.allDevicesWithNewAction); - - final MapEntry propertyWithAction = MapEntry( - tempAllDevicesWithNewActionList[0].value.key, - event.actionsName, - ); - - tempAllDevicesWithNewActionList[0] = - MapEntry(tempAllDevicesWithNewActionList[0].key, propertyWithAction); - - emit( - state.copyWith( - actionsName: event.actionsName, - allDevicesWithNewAction: tempAllDevicesWithNewActionList, - authFailureOrSuccessOption: none(), - ), - ); - } - } - - Future _changePropertyForDevices( - ChangePropertyForDevices event, - Emitter emit, - ) async { - if (state.allDevicesWithNewAction.isNotEmpty) { - final List>> - tempAllDevicesWithNewActionList = - List.from(state.allDevicesWithNewAction); - - final MapEntry propertyWithAction = MapEntry( - event.propertyOfDevice, - null, - ); - - tempAllDevicesWithNewActionList[0] = - MapEntry(tempAllDevicesWithNewActionList[0].key, propertyWithAction); - - emit( - state.copyWith( - propertyName: event.propertyOfDevice, - allDevicesWithNewAction: tempAllDevicesWithNewActionList, - authFailureOrSuccessOption: none(), - ), - ); - } - } -} diff --git a/lib/application/add_new_action/add_new_action_event.dart b/lib/application/add_new_action/add_new_action_event.dart deleted file mode 100644 index f3e1013b9..000000000 --- a/lib/application/add_new_action/add_new_action_event.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'add_new_action_bloc.dart'; - -@freezed -class AddNewActionEvent with _$AddNewActionEvent { - const factory AddNewActionEvent.actionsNameChange(String actionsName) = - ActionsNameChange; - - const factory AddNewActionEvent.changePropertyForDevices( - String propertyOfDevice, - ) = ChangePropertyForDevices; - - const factory AddNewActionEvent.changeActionDevices( - String actionForProperty, - ) = ChangeActionDevices; - - const factory AddNewActionEvent.initialized() = Initialized; -} diff --git a/lib/application/add_new_action/add_new_action_state.dart b/lib/application/add_new_action/add_new_action_state.dart deleted file mode 100644 index af838c8d4..000000000 --- a/lib/application/add_new_action/add_new_action_state.dart +++ /dev/null @@ -1,30 +0,0 @@ -part of 'add_new_action_bloc.dart'; - -@freezed -class AddNewActionState with _$AddNewActionState { - /// Will save the state with the values of the action that user want to preform - const factory AddNewActionState({ - required String actionsName, - required String propertyName, - required List allDevices, - - /// Will contain (in that order) device to change his property to change and the new value of this property - required List>> - allDevicesWithNewAction, - required List> allEntityActions, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _AddNewActionState; - - factory AddNewActionState.initial() => AddNewActionState( - actionsName: '', - propertyName: '', - allDevices: [], - allDevicesWithNewAction: [], - allEntityActions: [], - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/add_new_binding/add_new_binding_bloc.dart b/lib/application/add_new_binding/add_new_binding_bloc.dart deleted file mode 100644 index d1c720cdd..000000000 --- a/lib/application/add_new_binding/add_new_binding_bloc.dart +++ /dev/null @@ -1,124 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/binding/i_binding_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'add_new_binding_bloc.freezed.dart'; -part 'add_new_binding_event.dart'; -part 'add_new_binding_state.dart'; - -@injectable -class AddNewBindingBloc extends Bloc { - AddNewBindingBloc() : super(AddNewBindingState.initial()) { - on(_changeActionDevices); - on(_bindingNameChange); - on(_addDevicesWithNewActions); - on(_deleted); - on(_initialized); - on(_sendBindingToHub); - - add(const AddNewBindingEvent.initialized()); - } - - List _allDevices = []; - - String bindingName = ''; - List allDevices = []; - - /// List of devices with entities, will be treated as actions - List>> - allDevicesWithNewAction = []; - List> allEntityActions = []; - bool showErrorMessages = false; - bool isSubmitting = false; - Option> authFailureOrSuccessOption = none(); - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { - _allDevices = List.from(r.iter); - }); - _allDevices.removeWhere((element) => element == null); - - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: bindingName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _changeActionDevices( - ChangeActionDevices event, - Emitter emit, - ) async { - // for (final DeviceEntityAbstract? device in _allDevices) { - // if (device != null && event.deviceId == device.uniqueId.getOrCrash()) { - // emit( - // state.copyWith( - // allDevicesWithNewAction: [device], - // actionsName: '', - // authFailureOrSuccessOption: none(), - // ), - // ); - // } - // } - } - - Future _sendBindingToHub( - SendBindingToHub event, - Emitter emit, - ) async { - IBindingCbjRepository.instance - .addOrUpdateNewBindingInHubFromDevicesPropertyActionList( - bindingName, - allDevicesWithNewAction, - ); - } - - Future _bindingNameChange( - BindingNameChange event, - Emitter emit, - ) async { - bindingName = event.bindingName; - } - - Future _addDevicesWithNewActions( - AddDevicesWithNewActions event, - Emitter emit, - ) async { - allDevicesWithNewAction.addAll(event.smartDevicesWithActionToAdd); - - emit(const LoadInProgress()); - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: bindingName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} -} diff --git a/lib/application/add_new_binding/add_new_binding_event.dart b/lib/application/add_new_binding/add_new_binding_event.dart deleted file mode 100644 index 342d7fc07..000000000 --- a/lib/application/add_new_binding/add_new_binding_event.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'add_new_binding_bloc.dart'; - -@freezed -class AddNewBindingEvent with _$AddNewBindingEvent { - const factory AddNewBindingEvent.initialized() = Initialized; - - const factory AddNewBindingEvent.bindingNameChange(String bindingName) = - BindingNameChange; - - const factory AddNewBindingEvent.changeActionDevices(String deviceId) = - ChangeActionDevices; - - const factory AddNewBindingEvent.addDevicesWithNewActions( - List>> - smartDevicesWithActionToAdd, - ) = AddDevicesWithNewActions; - - const factory AddNewBindingEvent.deleted(GenericLightDE deviceEntity) = - Deleted; - - const factory AddNewBindingEvent.sendBindingToHub() = SendBindingToHub; -} diff --git a/lib/application/add_new_binding/add_new_binding_state.dart b/lib/application/add_new_binding/add_new_binding_state.dart deleted file mode 100644 index 8a2c7467b..000000000 --- a/lib/application/add_new_binding/add_new_binding_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'add_new_binding_bloc.dart'; - -@freezed -class AddNewBindingState with _$AddNewBindingState { - factory AddNewBindingState.initial() = Initial; - - const factory AddNewBindingState.loadPageState({ - required String actionsName, - required List allDevices, - required List>> - allDevicesWithNewAction, - required List> allEntityActions, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = LoadPageState; - - const factory AddNewBindingState.loadInProgress() = LoadInProgress; -} diff --git a/lib/application/add_new_routine/add_new_routine_bloc.dart b/lib/application/add_new_routine/add_new_routine_bloc.dart deleted file mode 100644 index 5835cadbe..000000000 --- a/lib/application/add_new_routine/add_new_routine_bloc.dart +++ /dev/null @@ -1,149 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/routine/i_routine_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/routine/value_objects_routine_cbj.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'add_new_routine_bloc.freezed.dart'; -part 'add_new_routine_event.dart'; -part 'add_new_routine_state.dart'; - -@injectable -class AddNewRoutineBloc extends Bloc { - AddNewRoutineBloc() : super(AddNewRoutineState.initial()) { - on(_addRoutineDate); - on(_changeActionDevices); - on(_routineNameChange); - on(_addDevicesWithNewActions); - on(_deleted); - on(_initialized); - on(_sendRoutineToHub); - - add(const AddNewRoutineEvent.initialized()); - } - - List _allDevices = []; - - String routineName = ''; - List allDevices = []; - - RoutineCbjRepeatDateDays? daysToRepeat; - RoutineCbjRepeatDateHour? hourToRepeat; - RoutineCbjRepeatDateMinute? minutesToRepeat; - - /// List of devices with entities, will be treated as actions - List>> - allDevicesWithNewAction = []; - List> allEntityActions = []; - bool showErrorMessages = false; - bool isSubmitting = false; - Option> authFailureOrSuccessOption = none(); - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { - _allDevices = List.from(r.iter); - }); - _allDevices.removeWhere((element) => element == null); - - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: routineName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _addRoutineDate( - AddRoutineDate event, - Emitter emit, - ) async { - daysToRepeat = event.daysToRepeat; - hourToRepeat = event.hourToRepeat; - minutesToRepeat = event.minutesToRepeat; - } - - Future _changeActionDevices( - ChangeActionDevices event, - Emitter emit, - ) async { - // for (final DeviceEntityAbstract? device in _allDevices) { - // if (device != null && event.deviceId == device.uniqueId.getOrCrash()) { - // emit( - // state.copyWith( - // allDevicesWithNewAction: [device], - // actionsName: '', - // authFailureOrSuccessOption: none(), - // ), - // ); - // } - // } - } - - Future _sendRoutineToHub( - SendRoutineToHub event, - Emitter emit, - ) async { - if (daysToRepeat == null || - hourToRepeat == null || - minutesToRepeat == null) { - emit(const AddNewRoutineFailure()); - - return; - } - IRoutineCbjRepository.instance - .addOrUpdateNewRoutineInHubFromDevicesPropertyActionList( - routineName, - allDevicesWithNewAction, - daysToRepeat!, - hourToRepeat!, - minutesToRepeat!, - ); - } - - Future _routineNameChange( - RoutineNameChange event, - Emitter emit, - ) async { - routineName = event.routineName; - } - - Future _addDevicesWithNewActions( - AddDevicesWithNewActions event, - Emitter emit, - ) async { - allDevicesWithNewAction.addAll(event.smartDevicesWithActionToAdd); - - emit(const LoadInProgress()); - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: routineName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} -} diff --git a/lib/application/add_new_routine/add_new_routine_event.dart b/lib/application/add_new_routine/add_new_routine_event.dart deleted file mode 100644 index 1e7e67e3e..000000000 --- a/lib/application/add_new_routine/add_new_routine_event.dart +++ /dev/null @@ -1,28 +0,0 @@ -part of 'add_new_routine_bloc.dart'; - -@freezed -class AddNewRoutineEvent with _$AddNewRoutineEvent { - const factory AddNewRoutineEvent.initialized() = Initialized; - - const factory AddNewRoutineEvent.addRoutineDate({ - required RoutineCbjRepeatDateDays? daysToRepeat, - required RoutineCbjRepeatDateHour? hourToRepeat, - required RoutineCbjRepeatDateMinute? minutesToRepeat, - }) = AddRoutineDate; - - const factory AddNewRoutineEvent.routineNameChange(String routineName) = - RoutineNameChange; - - const factory AddNewRoutineEvent.changeActionDevices(String deviceId) = - ChangeActionDevices; - - const factory AddNewRoutineEvent.addDevicesWithNewActions( - List>> - smartDevicesWithActionToAdd, - ) = AddDevicesWithNewActions; - - const factory AddNewRoutineEvent.deleted(GenericLightDE deviceEntity) = - Deleted; - - const factory AddNewRoutineEvent.sendRoutineToHub() = SendRoutineToHub; -} diff --git a/lib/application/add_new_routine/add_new_routine_state.dart b/lib/application/add_new_routine/add_new_routine_state.dart deleted file mode 100644 index fb422644f..000000000 --- a/lib/application/add_new_routine/add_new_routine_state.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'add_new_routine_bloc.dart'; - -@freezed -class AddNewRoutineState with _$AddNewRoutineState { - factory AddNewRoutineState.initial() = Initial; - - const factory AddNewRoutineState.loadPageState({ - required String actionsName, - required List allDevices, - required List>> - allDevicesWithNewAction, - required List> allEntityActions, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = LoadPageState; - - const factory AddNewRoutineState.loadInProgress() = LoadInProgress; - - const factory AddNewRoutineState.addNewRoutineFailure() = - AddNewRoutineFailure; -} diff --git a/lib/application/add_new_scene/add_new_scene_bloc.dart b/lib/application/add_new_scene/add_new_scene_bloc.dart deleted file mode 100644 index 5e1ae4402..000000000 --- a/lib/application/add_new_scene/add_new_scene_bloc.dart +++ /dev/null @@ -1,127 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'add_new_scene_bloc.freezed.dart'; -part 'add_new_scene_event.dart'; -part 'add_new_scene_state.dart'; - -@injectable -class AddNewSceneBloc extends Bloc { - AddNewSceneBloc() : super(AddNewSceneState.initial()) { - on(_changeActionDevices); - on(_sceneNameChange); - on(_addDevicesWithNewActions); - on(_deleted); - on(_initialized); - on(_sendSceneToHub); - - add(const AddNewSceneEvent.initialized()); - } - - List _allDevices = []; - - String sceneName = ''; - List allDevices = []; - - /// List of devices with entities, will be treated as actions - List>> - allDevicesWithNewAction = []; - List> allEntityActions = []; - bool showErrorMessages = false; - bool isSubmitting = false; - Option> authFailureOrSuccessOption = none(); - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { - _allDevices = List.from(r.iter); - }); - _allDevices.removeWhere((element) => element == null); - - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: sceneName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _changeActionDevices( - ChangeActionDevices event, - Emitter emit, - ) async { - // for (final DeviceEntityAbstract? device in _allDevices) { - // if (device != null && event.deviceId == device.uniqueId.getOrCrash()) { - // emit( - // state.copyWith( - // allDevicesWithNewAction: [device], - // actionsName: '', - // authFailureOrSuccessOption: none(), - // ), - // ); - // } - // } - } - - Future _sendSceneToHub( - SendSceneToHub event, - Emitter emit, - ) async { - ISceneCbjRepository.instance - .addOrUpdateNewSceneInHubFromDevicesPropertyActionList( - sceneName, - allDevicesWithNewAction, - // TODO: Check what value to use - AreaPurposesTypes.laundryRoom, - ); - } - - Future _sceneNameChange( - SceneNameChange event, - Emitter emit, - ) async { - sceneName = event.sceneName; - } - - Future _addDevicesWithNewActions( - AddDevicesWithNewActions event, - Emitter emit, - ) async { - allDevicesWithNewAction.addAll(event.smartDevicesWithActionToAdd); - - emit(const LoadInProgress()); - emit( - LoadPageState( - allDevices: _allDevices as List, - showErrorMessages: showErrorMessages, - isSubmitting: isSubmitting, - authFailureOrSuccessOption: authFailureOrSuccessOption, - allEntityActions: allEntityActions, - actionsName: sceneName, - allDevicesWithNewAction: allDevicesWithNewAction, - ), - ); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} -} diff --git a/lib/application/add_new_scene/add_new_scene_event.dart b/lib/application/add_new_scene/add_new_scene_event.dart deleted file mode 100644 index 3461714fa..000000000 --- a/lib/application/add_new_scene/add_new_scene_event.dart +++ /dev/null @@ -1,21 +0,0 @@ -part of 'add_new_scene_bloc.dart'; - -@freezed -class AddNewSceneEvent with _$AddNewSceneEvent { - const factory AddNewSceneEvent.initialized() = Initialized; - - const factory AddNewSceneEvent.sceneNameChange(String sceneName) = - SceneNameChange; - - const factory AddNewSceneEvent.changeActionDevices(String deviceId) = - ChangeActionDevices; - - const factory AddNewSceneEvent.addDevicesWithNewActions( - List>> - smartDevicesWithActionToAdd, - ) = AddDevicesWithNewActions; - - const factory AddNewSceneEvent.deleted(GenericLightDE deviceEntity) = Deleted; - - const factory AddNewSceneEvent.sendSceneToHub() = SendSceneToHub; -} diff --git a/lib/application/add_new_scene/add_new_scene_state.dart b/lib/application/add_new_scene/add_new_scene_state.dart deleted file mode 100644 index a07e41e3e..000000000 --- a/lib/application/add_new_scene/add_new_scene_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'add_new_scene_bloc.dart'; - -@freezed -class AddNewSceneState with _$AddNewSceneState { - factory AddNewSceneState.initial() = Initial; - - const factory AddNewSceneState.loadPageState({ - required String actionsName, - required List allDevices, - required List>> - allDevicesWithNewAction, - required List> allEntityActions, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = LoadPageState; - - const factory AddNewSceneState.loadInProgress() = LoadInProgress; -} diff --git a/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart b/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart deleted file mode 100644 index b4a0867e5..000000000 --- a/lib/application/folder_of_bindings/folder_of_bindings_bloc.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/binding/binding_cbj_entity.dart'; -import 'package:cbj_integrations_controller/domain/binding/i_binding_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'folder_of_bindings_bloc.freezed.dart'; -part 'folder_of_bindings_event.dart'; -part 'folder_of_bindings_state.dart'; - -@injectable -class FolderOfBindingsBloc - extends Bloc { - FolderOfBindingsBloc() : super(FolderOfBindingsState.initialized()) { - on(_initialized); - } - - late RoomEntity folderOfBindings; - - List allBindingsInTheRoom = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - folderOfBindings = event.folderOfBindings; - emit(const FolderOfBindingsState.loading()); - - final Map eitherAllBindings = - await IBindingCbjRepository.instance.getAllBindingsAsMap(); - for (final String bindingId - in folderOfBindings.roomBindingsId.getOrCrash()) { - if (eitherAllBindings.containsKey(bindingId)) { - allBindingsInTheRoom.add(eitherAllBindings[bindingId]!); - } - } - // eitherAllBindings.fold((l) => null, - // (HashMap bindingsList) { - // for (final String bindingId - // in folderOfBindings.roomBindingsId.getOrCrash()) { - // if (bindingsList.containsKey(bindingId)) { - // allBindingsInTheRoom.add(bindingsList[bindingId]!); - // } - // } - // }); - if (allBindingsInTheRoom.isEmpty) { - emit(const FolderOfBindingsState.loadedEmptyScens()); - return; - } - - emit(FolderOfBindingsState.loaded(bindingsList: allBindingsInTheRoom)); - } -} diff --git a/lib/application/folder_of_bindings/folder_of_bindings_event.dart b/lib/application/folder_of_bindings/folder_of_bindings_event.dart deleted file mode 100644 index f8bf7b118..000000000 --- a/lib/application/folder_of_bindings/folder_of_bindings_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'folder_of_bindings_bloc.dart'; - -@freezed -class FolderOfBindingsEvent with _$FolderOfBindingsEvent { - const factory FolderOfBindingsEvent.initialized({ - required RoomEntity folderOfBindings, - }) = Initialized; -} diff --git a/lib/application/folder_of_bindings/folder_of_bindings_state.dart b/lib/application/folder_of_bindings/folder_of_bindings_state.dart deleted file mode 100644 index 0dcc1fb16..000000000 --- a/lib/application/folder_of_bindings/folder_of_bindings_state.dart +++ /dev/null @@ -1,24 +0,0 @@ -part of 'folder_of_bindings_bloc.dart'; - -@freezed -class FolderOfBindingsState with _$FolderOfBindingsState { - const factory FolderOfBindingsState({ - String? testValue, - }) = _FolderOfBindingsState; - - factory FolderOfBindingsState.initialized() => const FolderOfBindingsState(); - - // factory FolderOfBindingsState.initialized({ - // required RoomEntity roomEntity, - // }) = FolderOfBindingsState; - - const factory FolderOfBindingsState.loading() = Loading; - - const factory FolderOfBindingsState.loaded({ - required List bindingsList, - }) = Loaded; - - const factory FolderOfBindingsState.loadedEmptyScens() = LoadedEmptyScens; - - const factory FolderOfBindingsState.error() = Error; -} diff --git a/lib/application/folder_of_routines/folder_of_routines_bloc.dart b/lib/application/folder_of_routines/folder_of_routines_bloc.dart deleted file mode 100644 index 8783eb3fe..000000000 --- a/lib/application/folder_of_routines/folder_of_routines_bloc.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/routine/i_routine_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/routine/routine_cbj_entity.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'folder_of_routines_bloc.freezed.dart'; -part 'folder_of_routines_event.dart'; -part 'folder_of_routines_state.dart'; - -@injectable -class FolderOfRoutinesBloc - extends Bloc { - FolderOfRoutinesBloc() : super(FolderOfRoutinesState.initialized()) { - on(_initialized); - } - - late RoomEntity folderOfRoutines; - - List allRoutinesInTheRoom = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - folderOfRoutines = event.folderOfRoutines; - emit(const FolderOfRoutinesState.loading()); - - final Map eitherAllRoutines = - await IRoutineCbjRepository.instance.getAllRoutinesAsMap(); - for (final String routineId - in folderOfRoutines.roomRoutinesId.getOrCrash()) { - if (eitherAllRoutines.containsKey(routineId)) { - allRoutinesInTheRoom.add(eitherAllRoutines[routineId]!); - } - } - // eitherAllRoutines.fold((l) => null, - // (HashMap routinesList) { - // for (final String routineId - // in folderOfRoutines.roomRoutinesId.getOrCrash()) { - // if (routinesList.containsKey(routineId)) { - // allRoutinesInTheRoom.add(routinesList[routineId]!); - // } - // } - // }); - if (allRoutinesInTheRoom.isEmpty) { - emit(const FolderOfRoutinesState.loadedEmptyScens()); - return; - } - - emit(FolderOfRoutinesState.loaded(routinesList: allRoutinesInTheRoom)); - } -} diff --git a/lib/application/folder_of_routines/folder_of_routines_event.dart b/lib/application/folder_of_routines/folder_of_routines_event.dart deleted file mode 100644 index 826b06a8f..000000000 --- a/lib/application/folder_of_routines/folder_of_routines_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'folder_of_routines_bloc.dart'; - -@freezed -class FolderOfRoutinesEvent with _$FolderOfRoutinesEvent { - const factory FolderOfRoutinesEvent.initialized({ - required RoomEntity folderOfRoutines, - }) = Initialized; -} diff --git a/lib/application/folder_of_routines/folder_of_routines_state.dart b/lib/application/folder_of_routines/folder_of_routines_state.dart deleted file mode 100644 index f09f82957..000000000 --- a/lib/application/folder_of_routines/folder_of_routines_state.dart +++ /dev/null @@ -1,24 +0,0 @@ -part of 'folder_of_routines_bloc.dart'; - -@freezed -class FolderOfRoutinesState with _$FolderOfRoutinesState { - const factory FolderOfRoutinesState({ - String? testValue, - }) = _FolderOfRoutinesState; - - factory FolderOfRoutinesState.initialized() => const FolderOfRoutinesState(); - - // factory FolderOfRoutinesState.initialized({ - // required RoomEntity roomEntity, - // }) = FolderOfRoutinesState; - - const factory FolderOfRoutinesState.loading() = Loading; - - const factory FolderOfRoutinesState.loaded({ - required List routinesList, - }) = Loaded; - - const factory FolderOfRoutinesState.loadedEmptyScens() = LoadedEmptyScens; - - const factory FolderOfRoutinesState.error() = Error; -} diff --git a/lib/application/folder_of_scenes/folder_of_scenes_bloc.dart b/lib/application/folder_of_scenes/folder_of_scenes_bloc.dart deleted file mode 100644 index 683791980..000000000 --- a/lib/application/folder_of_scenes/folder_of_scenes_bloc.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'folder_of_scenes_bloc.freezed.dart'; -part 'folder_of_scenes_event.dart'; -part 'folder_of_scenes_state.dart'; - -@injectable -class FolderOfScenesBloc - extends Bloc { - FolderOfScenesBloc() : super(FolderOfScenesState.initialized()) { - on(_initialized); - } - - late RoomEntity folderOfScenes; - - List allScenesInTheRoom = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - folderOfScenes = event.folderOfScenes; - emit(const FolderOfScenesState.loading()); - - final Map eitherAllScenes = - await ISceneCbjRepository.instance.getAllScenesAsMap(); - for (final String sceneId in folderOfScenes.roomScenesId.getOrCrash()) { - if (eitherAllScenes.containsKey(sceneId)) { - allScenesInTheRoom.add(eitherAllScenes[sceneId]!); - } - } - - // eitherAllScenes.fold((l) => null, - // (HashMap scenesList) { - // for (final String sceneId in folderOfScenes.roomScenesId.getOrCrash()) { - // if (scenesList.containsKey(sceneId)) { - // allScenesInTheRoom.add(scenesList[sceneId]!); - // } - // } - // }); - if (allScenesInTheRoom.isEmpty) { - emit(const FolderOfScenesState.loadedEmptyScens()); - return; - } - - emit(FolderOfScenesState.loaded(scenesList: allScenesInTheRoom)); - } -} diff --git a/lib/application/folder_of_scenes/folder_of_scenes_event.dart b/lib/application/folder_of_scenes/folder_of_scenes_event.dart deleted file mode 100644 index 225e8a280..000000000 --- a/lib/application/folder_of_scenes/folder_of_scenes_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'folder_of_scenes_bloc.dart'; - -@freezed -class FolderOfScenesEvent with _$FolderOfScenesEvent { - const factory FolderOfScenesEvent.initialized({ - required RoomEntity folderOfScenes, - }) = Initialized; -} diff --git a/lib/application/folder_of_scenes/folder_of_scenes_state.dart b/lib/application/folder_of_scenes/folder_of_scenes_state.dart deleted file mode 100644 index 7fd820dbc..000000000 --- a/lib/application/folder_of_scenes/folder_of_scenes_state.dart +++ /dev/null @@ -1,24 +0,0 @@ -part of 'folder_of_scenes_bloc.dart'; - -@freezed -class FolderOfScenesState with _$FolderOfScenesState { - const factory FolderOfScenesState({ - String? testValue, - }) = _FolderOfScenesState; - - factory FolderOfScenesState.initialized() => const FolderOfScenesState(); - - // factory FolderOfScenesState.initialized({ - // required RoomEntity roomEntity, - // }) = FolderOfScenesState; - - const factory FolderOfScenesState.loading() = Loading; - - const factory FolderOfScenesState.loaded({ - required List scenesList, - }) = Loaded; - - const factory FolderOfScenesState.loadedEmptyScens() = LoadedEmptyScens; - - const factory FolderOfScenesState.error() = Error; -} diff --git a/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart b/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart deleted file mode 100644 index 4d3faa7fb..000000000 --- a/lib/application/folders_of_bindings/folders_of_bindings_bloc.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/binding/binding_cbj_entity.dart'; -import 'package:cbj_integrations_controller/domain/binding/i_binding_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/collection.dart'; - -part 'folders_of_bindings_bloc.freezed.dart'; -part 'folders_of_bindings_event.dart'; -part 'folders_of_bindings_state.dart'; - -@injectable -class FoldersOfBindingsBloc - extends Bloc { - FoldersOfBindingsBloc() : super(FoldersOfBindingsState.initialized()) { - on(_initialized); - } - - List allBindings = []; - List allRoomsWithBindings = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const FoldersOfBindingsState.loading()); - - final List eitherAllBindings = - await IBindingCbjRepository.instance.getAllBindingsAsList(); - allBindings.addAll(eitherAllBindings); - - // eitherAllBindings.fold((l) => null, (r) { - // allBindings.addAll(r.asList()); - // }); - if (allBindings.isEmpty) { - return; - } - - final Either> eitherAllRooms = - await IRoomRepository.instance.getAllRooms(); - eitherAllRooms.fold((l) => null, (KtList r) { - for (final RoomEntity rE in r.asList()) { - if (rE.roomBindingsId.getOrCrash().isNotEmpty) { - allRoomsWithBindings.add(rE); - } - } - }); - - if (allRoomsWithBindings.isEmpty) { - emit(const FoldersOfBindingsState.loadedEmpty()); - - return; - } - - emit(FoldersOfBindingsState.loaded(allRoomsWithBindings)); - } -} diff --git a/lib/application/folders_of_bindings/folders_of_bindings_event.dart b/lib/application/folders_of_bindings/folders_of_bindings_event.dart deleted file mode 100644 index f836fa3f5..000000000 --- a/lib/application/folders_of_bindings/folders_of_bindings_event.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'folders_of_bindings_bloc.dart'; - -@freezed -class FoldersOfBindingsEvent with _$FoldersOfBindingsEvent { - const factory FoldersOfBindingsEvent.initialized() = Initialized; -} diff --git a/lib/application/folders_of_bindings/folders_of_bindings_state.dart b/lib/application/folders_of_bindings/folders_of_bindings_state.dart deleted file mode 100644 index 06cadac8e..000000000 --- a/lib/application/folders_of_bindings/folders_of_bindings_state.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'folders_of_bindings_bloc.dart'; - -@freezed -class FoldersOfBindingsState with _$FoldersOfBindingsState { - const factory FoldersOfBindingsState({ - required Option> authFailureOrSuccessOption, - }) = _FoldersOfBindingsState; - - factory FoldersOfBindingsState.initialized() => FoldersOfBindingsState( - authFailureOrSuccessOption: none(), - ); - - const factory FoldersOfBindingsState.loading() = Loading; - - const factory FoldersOfBindingsState.loaded( - List foldersOfBindings, - ) = Loaded; - - const factory FoldersOfBindingsState.loadedEmpty() = LoadedEmpty; - - const factory FoldersOfBindingsState.error() = Error; -} diff --git a/lib/application/folders_of_routines/folders_of_routines_bloc.dart b/lib/application/folders_of_routines/folders_of_routines_bloc.dart deleted file mode 100644 index 0770bf7df..000000000 --- a/lib/application/folders_of_routines/folders_of_routines_bloc.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; -import 'package:cbj_integrations_controller/domain/routine/i_routine_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/routine/routine_cbj_entity.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/collection.dart'; - -part 'folders_of_routines_bloc.freezed.dart'; -part 'folders_of_routines_event.dart'; -part 'folders_of_routines_state.dart'; - -@injectable -class FoldersOfRoutinesBloc - extends Bloc { - FoldersOfRoutinesBloc() : super(FoldersOfRoutinesState.initialized()) { - on(_initialized); - } - - List allRoutines = []; - List allRoomsWithRoutines = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const FoldersOfRoutinesState.loading()); - - final List eitherAllRoutines = - await IRoutineCbjRepository.instance.getAllRoutinesAsList(); - allRoutines.addAll(eitherAllRoutines); - - // eitherAllRoutines.fold((l) => null, (r) { - // allRoutines.addAll(r.asList()); - // }); - if (allRoutines.isEmpty) { - return; - } - - final Either> eitherAllRooms = - await IRoomRepository.instance.getAllRooms(); - eitherAllRooms.fold((l) => null, (KtList r) { - for (final RoomEntity rE in r.asList()) { - if (rE.roomRoutinesId.getOrCrash().isNotEmpty) { - allRoomsWithRoutines.add(rE); - } - } - }); - - if (allRoomsWithRoutines.isEmpty) { - emit(const FoldersOfRoutinesState.loadedEmpty()); - - return; - } - - emit(FoldersOfRoutinesState.loaded(allRoomsWithRoutines)); - } -} diff --git a/lib/application/folders_of_routines/folders_of_routines_event.dart b/lib/application/folders_of_routines/folders_of_routines_event.dart deleted file mode 100644 index 262daa7c9..000000000 --- a/lib/application/folders_of_routines/folders_of_routines_event.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'folders_of_routines_bloc.dart'; - -@freezed -class FoldersOfRoutinesEvent with _$FoldersOfRoutinesEvent { - const factory FoldersOfRoutinesEvent.initialized() = Initialized; -} diff --git a/lib/application/folders_of_routines/folders_of_routines_state.dart b/lib/application/folders_of_routines/folders_of_routines_state.dart deleted file mode 100644 index bf8b61388..000000000 --- a/lib/application/folders_of_routines/folders_of_routines_state.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'folders_of_routines_bloc.dart'; - -@freezed -class FoldersOfRoutinesState with _$FoldersOfRoutinesState { - const factory FoldersOfRoutinesState({ - required Option> authFailureOrSuccessOption, - }) = _FoldersOfRoutinesState; - - factory FoldersOfRoutinesState.initialized() => FoldersOfRoutinesState( - authFailureOrSuccessOption: none(), - ); - - const factory FoldersOfRoutinesState.loading() = Loading; - - const factory FoldersOfRoutinesState.loaded( - List foldersOfRoutines, - ) = Loaded; - - const factory FoldersOfRoutinesState.loadedEmpty() = LoadedEmpty; - - const factory FoldersOfRoutinesState.error() = Error; -} diff --git a/lib/application/folders_of_scenes/folders_of_scenes_bloc.dart b/lib/application/folders_of_scenes/folders_of_scenes_bloc.dart deleted file mode 100644 index cf80e6393..000000000 --- a/lib/application/folders_of_scenes/folders_of_scenes_bloc.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; -import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/collection.dart'; - -part 'folders_of_scenes_bloc.freezed.dart'; -part 'folders_of_scenes_event.dart'; -part 'folders_of_scenes_state.dart'; - -@injectable -class FoldersOfScenesBloc - extends Bloc { - FoldersOfScenesBloc() : super(FoldersOfScenesState.initialized()) { - on(_initialized); - } - - List allScenes = []; - List allRoomsWithScenes = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const FoldersOfScenesState.loading()); - - final List eitherAllScenes = - await ISceneCbjRepository.instance.getAllScenesAsList(); - allScenes.addAll(eitherAllScenes); - - // eitherAllScenes.fold((l) => null, (r) { - // allScenes.addAll(r.asList()); - // }); - if (allScenes.isEmpty) { - return; - } - - final Either> eitherAllRooms = - await IRoomRepository.instance.getAllRooms(); - eitherAllRooms.fold((l) => null, (KtList r) { - for (final RoomEntity rE in r.asList()) { - if (rE.roomScenesId.getOrCrash().isNotEmpty) { - allRoomsWithScenes.add(rE); - } - } - }); - - if (allRoomsWithScenes.isEmpty) { - emit(const FoldersOfScenesState.loadedEmpty()); - - return; - } - - emit(FoldersOfScenesState.loaded(allRoomsWithScenes)); - } -} diff --git a/lib/application/folders_of_scenes/folders_of_scenes_event.dart b/lib/application/folders_of_scenes/folders_of_scenes_event.dart deleted file mode 100644 index 7a16f981e..000000000 --- a/lib/application/folders_of_scenes/folders_of_scenes_event.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'folders_of_scenes_bloc.dart'; - -@freezed -class FoldersOfScenesEvent with _$FoldersOfScenesEvent { - const factory FoldersOfScenesEvent.initialized() = Initialized; -} diff --git a/lib/application/folders_of_scenes/folders_of_scenes_state.dart b/lib/application/folders_of_scenes/folders_of_scenes_state.dart deleted file mode 100644 index 9d4d35163..000000000 --- a/lib/application/folders_of_scenes/folders_of_scenes_state.dart +++ /dev/null @@ -1,22 +0,0 @@ -part of 'folders_of_scenes_bloc.dart'; - -@freezed -class FoldersOfScenesState with _$FoldersOfScenesState { - const factory FoldersOfScenesState({ - required Option> authFailureOrSuccessOption, - }) = _FoldersOfScenesState; - - factory FoldersOfScenesState.initialized() => FoldersOfScenesState( - authFailureOrSuccessOption: none(), - ); - - const factory FoldersOfScenesState.loading() = Loading; - - const factory FoldersOfScenesState.loaded( - List foldersOfScenes, - ) = Loaded; - - const factory FoldersOfScenesState.loadedEmpty() = LoadedEmpty; - - const factory FoldersOfScenesState.error() = Error; -} diff --git a/lib/application/join_home_by_id/join_home_by_id_bloc.dart b/lib/application/join_home_by_id/join_home_by_id_bloc.dart deleted file mode 100644 index 02b6c260b..000000000 --- a/lib/application/join_home_by_id/join_home_by_id_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_value_objects.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'join_home_by_id_bloc.freezed.dart'; -part 'join_home_by_id_event.dart'; -part 'join_home_by_id_state.dart'; - -@injectable -class JoinHomeByIdBloc extends Bloc { - JoinHomeByIdBloc() : super(JoinHomeByIdState.initialized()) { - on(_initialized); - on(_addHomeById); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - // emit( initialization.fold( - // () => const InitializeHomeState.error(), - // (_) => const InitializeHomeState.loaded(), - // ); - } - - Future _addHomeById( - AddHomeById event, - Emitter emit, - ) async { - emit(const JoinHomeByIdState.loading()); - - final getCurrentUser = (await IUserRepository.instance.getCurrentUser()) - .fold((l) => null, (r) => r); - if (getCurrentUser == null) { - emit(const JoinHomeByIdState.error()); - } else { - final AllHomesOfUserEntity allHomesOfUserEntity = AllHomesOfUserEntity( - id: AllHomesOfUserUniqueId.fromUniqueString(event.id), - name: AllHomesOfUserName('home'), - ); - final initialization = await IUserRepository.instance.addHome( - getCurrentUser, - allHomesOfUserEntity, - ); - emit( - initialization.fold( - (l) => const JoinHomeByIdState.error(), - (r) => const JoinHomeByIdState.loaded(), - ), - ); - } - } -} diff --git a/lib/application/join_home_by_id/join_home_by_id_event.dart b/lib/application/join_home_by_id/join_home_by_id_event.dart deleted file mode 100644 index 55a78f860..000000000 --- a/lib/application/join_home_by_id/join_home_by_id_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'join_home_by_id_bloc.dart'; - -@freezed -class JoinHomeByIdEvent with _$JoinHomeByIdEvent { - const factory JoinHomeByIdEvent.initialized() = Initialized; - - const factory JoinHomeByIdEvent.addHomeById(String id) = AddHomeById; -} diff --git a/lib/application/join_home_by_id/join_home_by_id_state.dart b/lib/application/join_home_by_id/join_home_by_id_state.dart deleted file mode 100644 index a12e5ba4d..000000000 --- a/lib/application/join_home_by_id/join_home_by_id_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'join_home_by_id_bloc.dart'; - -@freezed -class JoinHomeByIdState with _$JoinHomeByIdState { - const factory JoinHomeByIdState({ - required Option> authFailureOrSuccessOption, - }) = _JoinHomeByIdState; - - factory JoinHomeByIdState.initialized() => JoinHomeByIdState( - authFailureOrSuccessOption: none(), - ); - - const factory JoinHomeByIdState.loading() = Loading; - - const factory JoinHomeByIdState.loaded() = Loaded; - - const factory JoinHomeByIdState.error() = Error; -} diff --git a/lib/application/manage_access_point/manage_access_point_bloc.dart b/lib/application/manage_access_point/manage_access_point_bloc.dart deleted file mode 100644 index 4d5d8e618..000000000 --- a/lib/application/manage_access_point/manage_access_point_bloc.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'dart:async'; -import 'dart:io'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'manage_access_point_bloc.freezed.dart'; -part 'manage_access_point_event.dart'; -part 'manage_access_point_state.dart'; - -@injectable -class ManageAccessPointBloc - extends Bloc { - ManageAccessPointBloc() : super(ManageAccessPointState.initial()) { - on(_initialized); - on(_doesAccessPointOpen); - } - - ManageWiFiName? wifiName; - ManageWiFiPass? wifiPassword; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(ManageAccessPointState.loading()); - - if (Platform.isAndroid) { - final ManageNetworkEntity manageNetworkEntity = ManageNetworkEntity( - name: ManageWiFiName('CyBear Jinni'), - pass: ManageWiFiPass('CyBear Jinni'), - ); - - final Either openedAccessPoint = - await IManageNetworkRepository.instance - .openAccessPoint(manageNetworkEntity); - - emit( - openedAccessPoint.fold( - (f) => ManageAccessPointState.iOSDevice(), - (r) => ManageAccessPointState.loaded(), - ), - ); - } else { - emit(ManageAccessPointState.iOSDevice()); - } - } - - Future _doesAccessPointOpen( - DoesAccessPointOpen event, - Emitter emit, - ) async { - emit(ManageAccessPointState.loading()); - - if (Platform.isAndroid) { - final Either openedAccessPoint = - await IManageNetworkRepository.instance.doesAccessPointOpen(); - - emit( - openedAccessPoint.fold( - (HomeUserFailures f) { - if (f == const HomeUserFailures.accessPointIsNotOpen()) { - return ManageAccessPointState.accessPointIsNotOpen(); - } - return ManageAccessPointState.cantDetermineAccessPointOpenOrNot(); - }, - (r) => ManageAccessPointState.accessPointIsOpen(), - ), - ); - } else { - emit(ManageAccessPointState.cantDetermineAccessPointOpenOrNot()); - } - } -} diff --git a/lib/application/manage_access_point/manage_access_point_event.dart b/lib/application/manage_access_point/manage_access_point_event.dart deleted file mode 100644 index 094c6366e..000000000 --- a/lib/application/manage_access_point/manage_access_point_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'manage_access_point_bloc.dart'; - -@freezed -class ManageAccessPointEvent with _$ManageAccessPointEvent { - factory ManageAccessPointEvent.initialized() = Initialized; - - factory ManageAccessPointEvent.doesAccessPointOpen() = DoesAccessPointOpen; -} diff --git a/lib/application/manage_access_point/manage_access_point_state.dart b/lib/application/manage_access_point/manage_access_point_state.dart deleted file mode 100644 index 73915977b..000000000 --- a/lib/application/manage_access_point/manage_access_point_state.dart +++ /dev/null @@ -1,21 +0,0 @@ -part of 'manage_access_point_bloc.dart'; - -@freezed -class ManageAccessPointState with _$ManageAccessPointState { - factory ManageAccessPointState.initial() = Initial; - - factory ManageAccessPointState.loading() = Loading; - - factory ManageAccessPointState.loaded() = Loaded; - - factory ManageAccessPointState.iOSDevice() = IOSDevice; - - factory ManageAccessPointState.cantDetermineAccessPointOpenOrNot() = - CantDetermineAccessPointOpenOrNot; - - factory ManageAccessPointState.accessPointIsNotOpen() = AccessPointIsNotOpen; - - factory ManageAccessPointState.accessPointIsOpen() = AccessPointIsOpen; - - factory ManageAccessPointState.error() = Error; -} diff --git a/lib/application/manage_users/manage_users_bloc.dart b/lib/application/manage_users/manage_users_bloc.dart deleted file mode 100644 index 89baf6f1c..000000000 --- a/lib/application/manage_users/manage_users_bloc.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/home_user/i_home_user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'manage_users_bloc.freezed.dart'; -part 'manage_users_event.dart'; -part 'manage_users_state.dart'; - -@injectable -class ManageUsersBloc extends Bloc { - ManageUsersBloc() : super(const ManageUsersState.initial()) { - on(_initialized); - on(_userReceived); - on(_addByEmail); - on(_deleted); - } - - StreamSubscription>>? - _userStreamSubscription; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const ManageUsersState.inProgress()); - await _userStreamSubscription?.cancel(); - _userStreamSubscription = IHomeUserRepository.instance.getAllUsers().listen( - (allUsersEvent) => add(ManageUsersEvent.userReceived(allUsersEvent)), - ); - } - - Future _userReceived( - UserReceived event, - Emitter emit, - ) async { - emit(const ManageUsersState.inProgress()); - - emit( - event.failureOrUsers.fold( - (f) => ManageUsersState.loadFailure(f), - (user) => ManageUsersState.loadSuccess(user), - ), - ); - } - - Future _addByEmail( - AddByEmail event, - Emitter emit, - ) async {} - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - @override - Future close() async { - await _userStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/manage_users/manage_users_event.dart b/lib/application/manage_users/manage_users_event.dart deleted file mode 100644 index c90dd68c7..000000000 --- a/lib/application/manage_users/manage_users_event.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'manage_users_bloc.dart'; - -@freezed -class ManageUsersEvent with _$ManageUsersEvent { - const factory ManageUsersEvent.initialized() = Initialized; - - const factory ManageUsersEvent.addByEmail(String mail) = AddByEmail; - - const factory ManageUsersEvent.userReceived( - Either> failureOrUsers, - ) = UserReceived; - - const factory ManageUsersEvent.deleted(HomeUserEntity homeUserEntity) = - Deleted; -} diff --git a/lib/application/manage_users/manage_users_state.dart b/lib/application/manage_users/manage_users_state.dart deleted file mode 100644 index e4a8b9fdf..000000000 --- a/lib/application/manage_users/manage_users_state.dart +++ /dev/null @@ -1,24 +0,0 @@ -part of 'manage_users_bloc.dart'; - -@freezed -class ManageUsersState with _$ManageUsersState { - const factory ManageUsersState.initial() = _Initial; - - const factory ManageUsersState.inProgress() = _InProgress; - - const factory ManageUsersState.loadSuccess(KtList homeUsers) = - _LoadSuccess; - - const factory ManageUsersState.addSuccess(String email) = _AddSuccess; - - const factory ManageUsersState.deleteFailure( - HomeUserFailures homeUserFailures, - ) = _DeleteFailure; - - const factory ManageUsersState.deleteSuccess() = _DeleteSuccess; - - const factory ManageUsersState.loadFailure(HomeUserFailures homeUserFailure) = - _loadFailure; - - const factory ManageUsersState.error() = Error; -} diff --git a/lib/application/more_connections_options/more_connections_options_bloc.dart b/lib/application/more_connections_options/more_connections_options_bloc.dart deleted file mode 100644 index ee8a41ed6..000000000 --- a/lib/application/more_connections_options/more_connections_options_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:auto_route/auto_route.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/widgets.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'more_connections_options_bloc.freezed.dart'; -part 'more_connections_options_event.dart'; -part 'more_connections_options_state.dart'; - -@injectable -class MoreConnectionsOptionsBloc - extends Bloc { - MoreConnectionsOptionsBloc() : super(MoreConnectionsOptionsState.initial()) { - on(_initialEvent); - on(_connectToRemotePipes); - on(_connectInDemoMode); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - late BuildContext context; - - Future _initialEvent( - InitialEvent event, - Emitter emit, - ) async { - context = event.context; - } - - Future _connectToRemotePipes( - ConnectToRemotePipes event, - Emitter emit, - ) async {} - - Future _connectInDemoMode( - ConnectInDemoMode event, - Emitter emit, - ) async { - context.router.replace(const HomeRoute()); - IHubConnectionRepository.instance.connectWithHub(demoMod: true); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - - return super.close(); - } -} diff --git a/lib/application/more_connections_options/more_connections_options_event.dart b/lib/application/more_connections_options/more_connections_options_event.dart deleted file mode 100644 index bb3c7498b..000000000 --- a/lib/application/more_connections_options/more_connections_options_event.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'more_connections_options_bloc.dart'; - -@freezed -class MoreConnectionsOptionsEvent with _$MoreConnectionsOptionsEvent { - const factory MoreConnectionsOptionsEvent.initialEvent(BuildContext context) = - InitialEvent; - - const factory MoreConnectionsOptionsEvent.connectToRemotePipes() = - ConnectToRemotePipes; - - const factory MoreConnectionsOptionsEvent.connectInDemoMode() = - ConnectInDemoMode; -} diff --git a/lib/application/more_connections_options/more_connections_options_state.dart b/lib/application/more_connections_options/more_connections_options_state.dart deleted file mode 100644 index 96d6e2ffa..000000000 --- a/lib/application/more_connections_options/more_connections_options_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'more_connections_options_bloc.dart'; - -@freezed -class MoreConnectionsOptionsState with _$MoreConnectionsOptionsState { - factory MoreConnectionsOptionsState.initial() = _Initial; - - const factory MoreConnectionsOptionsState.loadInProgress() = _LoadInProgress; - - const factory MoreConnectionsOptionsState.loadSuccess() = _loadSuccess; - - const factory MoreConnectionsOptionsState.loadFailure( - HubFailures hubFailure, - ) = _loadFailure; -} diff --git a/lib/application/remote_pipes/remote_pipes_bloc.dart b/lib/application/remote_pipes/remote_pipes_bloc.dart deleted file mode 100644 index eb81755aa..000000000 --- a/lib/application/remote_pipes/remote_pipes_bloc.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/remote_pipes/i_remote_pipes_repository.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_value_objects.dart'; -import 'package:flutter/widgets.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'remote_pipes_bloc.freezed.dart'; -part 'remote_pipes_event.dart'; -part 'remote_pipes_state.dart'; - -@injectable -class RemotePipesBloc extends Bloc { - RemotePipesBloc() : super(RemotePipesState.initial()) { - on(_initialized); - on(_remotePipesDomainChanged); - on(_permissionChanged); - on(_addRemotePipeUrl); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _remotePipesDomainChanged( - RemotePipesDomainChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - remotePipesDomainName: RemotePipesDomain(event.remotePipesDomain), - ), - ); - } - - Future _permissionChanged( - PermissionChanged event, - Emitter emit, - ) async { - // emit( state.copyWith( - // permission: AddUserPermission(e.permission), - // addUserFailureOrSuccessOption: none(), - // ); - } - - Future _addRemotePipeUrl( - AddRemotePipeUrl event, - Emitter emit, - ) async { - final RemotePipesEntity remotePipesEntity = - RemotePipesEntity.empty().copyWith( - domainName: RemotePipesDomain( - state.remotePipesDomainName.getOrCrash(), - ), - ); - - Navigator.pop(event.context); - await IRemotePipesRepository.instance - .setRemotePipesDomainName(remotePipesEntity); - } -} diff --git a/lib/application/remote_pipes/remote_pipes_event.dart b/lib/application/remote_pipes/remote_pipes_event.dart deleted file mode 100644 index 12887a1b0..000000000 --- a/lib/application/remote_pipes/remote_pipes_event.dart +++ /dev/null @@ -1,16 +0,0 @@ -part of 'remote_pipes_bloc.dart'; - -@freezed -class RemotePipesEvent with _$RemotePipesEvent { - const factory RemotePipesEvent.initialized() = Initialized; - - const factory RemotePipesEvent.remotePipesDomainChanged( - String remotePipesDomain, - ) = RemotePipesDomainChanged; - - const factory RemotePipesEvent.permissionChanged(String permission) = - PermissionChanged; - - const factory RemotePipesEvent.addRemotePipeUrl(BuildContext context) = - AddRemotePipeUrl; -} diff --git a/lib/application/remote_pipes/remote_pipes_state.dart b/lib/application/remote_pipes/remote_pipes_state.dart deleted file mode 100644 index 103830c5d..000000000 --- a/lib/application/remote_pipes/remote_pipes_state.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'remote_pipes_bloc.dart'; - -@freezed -class RemotePipesState with _$RemotePipesState { - const factory RemotePipesState({ - required RemotePipesDomain remotePipesDomainName, - }) = _RemotePipesState; - - factory RemotePipesState.initial() => RemotePipesState( - remotePipesDomainName: RemotePipesDomain(''), - ); -} diff --git a/lib/domain/create_home/create_home_entity.dart b/lib/domain/create_home/create_home_entity.dart deleted file mode 100644 index 7d9603d8f..000000000 --- a/lib/domain/create_home/create_home_entity.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:cybear_jinni/domain/create_home/create_home_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'create_home_entity.freezed.dart'; - -@freezed -class CreateHomeEntity with _$CreateHomeEntity { - const factory CreateHomeEntity({ - required HomeUniqueId id, - required HomeName name, - HomeDevicesUserId? homeDevicesUserId, - HomeDevicesUserEmail? homeDevicesUserEmail, - HomeDevicesUserPassword? homeDevicesUserPassword, - }) = _CreateHomeEntity; -} diff --git a/lib/domain/create_home/create_home_errors.dart b/lib/domain/create_home/create_home_errors.dart deleted file mode 100644 index ac73c073e..000000000 --- a/lib/domain/create_home/create_home_errors.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; - -class CreateHomeUnexpectedValueError extends Error { - CreateHomeUnexpectedValueError(this.createValueFailure); - - final CreateHomeFailure createValueFailure; - - @override - String toString() { - const explanation = - 'Encountered a ValueFailure at an unrecoverable point. Terminating.'; - return Error.safeToString('$explanation Failure was: $createValueFailure'); - } -} diff --git a/lib/domain/create_home/create_home_failure.dart b/lib/domain/create_home/create_home_failure.dart deleted file mode 100644 index 0094f23a8..000000000 --- a/lib/domain/create_home/create_home_failure.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'create_home_failure.freezed.dart'; - -@freezed -class CreateHomeFailure { - const factory CreateHomeFailure.empty({ - required T failedValue, - }) = _Empty; - - const factory CreateHomeFailure.unexpected({ - required T failedValue, - }) = _Unexpected; - - const factory CreateHomeFailure.devicesUserEmailIsInvalid() = - _DevicesUserEmailIsInvalid; - - const factory CreateHomeFailure.insufficientPermission() = - _InsufficientPermission; - - const factory CreateHomeFailure.unableToUpdate({ - required T failedValue, - }) = _UnableToUpdate; -} diff --git a/lib/domain/create_home/create_home_validators.dart b/lib/domain/create_home/create_home_validators.dart deleted file mode 100644 index 3c67a946f..000000000 --- a/lib/domain/create_home/create_home_validators.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:cbj_integrations_controller/domain/core/failures.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; -import 'package:dartz/dartz.dart'; - -Either, String> validateCreateHomeNotEmpty( - String input, -) { - if (input.isNotEmpty) { - return right(input); - } else { - return left( - CreateHomeFailure.empty( - failedValue: input, - ), - ); - } -} - -Either, String> validateUserAuth() { - return right('true'); -} diff --git a/lib/domain/create_home/create_home_value_objects.dart b/lib/domain/create_home/create_home_value_objects.dart deleted file mode 100644 index 266645f8c..000000000 --- a/lib/domain/create_home/create_home_value_objects.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'package:cybear_jinni/domain/create_home/create_home_errors.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_validators.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:uuid/uuid.dart'; - -@immutable -abstract class CreateHomeValueObjectAbstract { - const CreateHomeValueObjectAbstract(); - - Either, T> get value; - - /// Throws [UnexpectedValueError] containing the [CreateHomeFailure] - T getOrCrash() { - // id = identity - same as writing (right) => right - return value.fold((f) => throw CreateHomeUnexpectedValueError(f), id); - } - - Either, Unit> get failureOrUnit { - return value.fold((l) => left(l), (r) => right(unit)); - } - - bool isValid() => value.isRight(); - - @override - String toString() => 'Value($value)'; - - @override - @nonVirtual - bool operator ==(Object o) { - if (identical(this, o)) return true; - return o is CreateHomeValueObjectAbstract && o.value == value; - } - - @override - int get hashCode => value.hashCode; -} - -class HomeUniqueId extends CreateHomeValueObjectAbstract { - factory HomeUniqueId() { - return HomeUniqueId._(right(const Uuid().v1())); - } - - factory HomeUniqueId.fromUniqueString(String uniqueId) { - return HomeUniqueId._(right(uniqueId)); - } - - const HomeUniqueId._(this.value); - - @override - final Either, String> value; -} - -class HomeName extends CreateHomeValueObjectAbstract { - factory HomeName(String input) { - return HomeName._( - validateCreateHomeNotEmpty(input), - ); - } - - const HomeName._(this.value); - - @override - final Either, String> value; -} - -class HomeDevicesUserId extends CreateHomeValueObjectAbstract { - factory HomeDevicesUserId() { - return HomeDevicesUserId._(right(const Uuid().v1())); - } - - const HomeDevicesUserId._(this.value); - - factory HomeDevicesUserId.fromUniqueString(String uniqueId) { - return HomeDevicesUserId._(right(uniqueId)); - } - - @override - final Either, String> value; -} - -class HomeDevicesUserEmail extends CreateHomeValueObjectAbstract { - factory HomeDevicesUserEmail(String input) { - return HomeDevicesUserEmail._( - validateCreateHomeNotEmpty(input), - ); - } - - const HomeDevicesUserEmail._(this.value); - - @override - final Either, String> value; -} - -class HomeDevicesUserPassword extends CreateHomeValueObjectAbstract { - factory HomeDevicesUserPassword() { - return HomeDevicesUserPassword._(right(const Uuid().v1())); - } - - factory HomeDevicesUserPassword.fromUniqueString(String uniqueId) { - return HomeDevicesUserPassword._(right(uniqueId)); - } - - const HomeDevicesUserPassword._(this.value); - - @override - final Either, String> value; -} diff --git a/lib/domain/create_home/i_create_home_repository.dart b/lib/domain/create_home/i_create_home_repository.dart deleted file mode 100644 index 2b83f7c9c..000000000 --- a/lib/domain/create_home/i_create_home_repository.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:cybear_jinni/domain/create_home/create_home_entity.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/infrastructure/create_home/create_home_repository.dart'; -import 'package:dartz/dartz.dart'; - -abstract interface class ICreateHomeRepository { - static ICreateHomeRepository? _instance; - - static ICreateHomeRepository get instance { - return _instance ??= CreateHomeRepository(); - } - - Future> createNewHome( - CreateHomeEntity createHomeEntity, - ); - - Future> addUserToHome(UserEntity userEntity); - - Future> addDeviceUserToHome( - CreateHomeEntity createHomeEntity, - ); - - Future> getDeviceUserFromHome(); - - Future> getFirstWifi(); -} diff --git a/lib/domain/remote_pipes/i_remote_pipes_repository.dart b/lib/domain/remote_pipes/i_remote_pipes_repository.dart deleted file mode 100644 index 27fa0bf70..000000000 --- a/lib/domain/remote_pipes/i_remote_pipes_repository.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_repository.dart'; -import 'package:dartz/dartz.dart'; - -abstract interface class IRemotePipesRepository { - static IRemotePipesRepository? _instance; - - static IRemotePipesRepository get instance { - return _instance ??= RemotePipesRepository(); - } - - Future> setRemotePipesDomainName( - RemotePipesEntity remotePipesEntity, - ); -} diff --git a/lib/domain/remote_pipes/remote_pipes_entity.dart b/lib/domain/remote_pipes/remote_pipes_entity.dart deleted file mode 100644 index e91e2ac90..000000000 --- a/lib/domain/remote_pipes/remote_pipes_entity.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_value_objects.dart'; -import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_dtos.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'remote_pipes_entity.freezed.dart'; - -@freezed -abstract class RemotePipesEntity implements _$RemotePipesEntity { - const factory RemotePipesEntity({ - required RemotePipesDomain? domainName, - }) = _RemotePipesEntity; - - const RemotePipesEntity._(); - - factory RemotePipesEntity.empty() => RemotePipesEntity( - domainName: RemotePipesDomain(''), - ); - - Option> get failureOption { - return domainName!.value.fold((f) => some(f), (_) => none()); - } - - RemotePipesDtos toInfrastructure() { - return RemotePipesDtos( - domainName: domainName!.getOrCrash(), - - // serverTimeStamp: FieldValue.serverTimestamp(), - ); - } -} diff --git a/lib/domain/remote_pipes/remote_pipes_errors.dart b/lib/domain/remote_pipes/remote_pipes_errors.dart deleted file mode 100644 index d20ae0e1a..000000000 --- a/lib/domain/remote_pipes/remote_pipes_errors.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; - -class RemotePipesUnexpectedValueError extends Error { - RemotePipesUnexpectedValueError(this.homeUserValueFailure); - - final RemotePipesFailures homeUserValueFailure; - - @override - String toString() { - const explanation = - 'Encountered a ValueFailure at an unrecoverable point. Terminating.'; - return Error.safeToString( - '$explanation Failure was: $homeUserValueFailure', - ); - } -} diff --git a/lib/domain/remote_pipes/remote_pipes_failures.dart b/lib/domain/remote_pipes/remote_pipes_failures.dart deleted file mode 100644 index 3f6e56a50..000000000 --- a/lib/domain/remote_pipes/remote_pipes_failures.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'remote_pipes_failures.freezed.dart'; - -@freezed -class RemotePipesFailures { - const factory RemotePipesFailures.empty({ - required T failedValue, - }) = _Empty; - - const factory RemotePipesFailures.unexpected() = _Unexpected; - - const factory RemotePipesFailures.insufficientPermission() = - _InsufficientPermission; - - const factory RemotePipesFailures.unableToUpdate() = _UnableToUpdate; -} diff --git a/lib/domain/remote_pipes/remote_pipes_validators.dart b/lib/domain/remote_pipes/remote_pipes_validators.dart deleted file mode 100644 index 9a0fa4fda..000000000 --- a/lib/domain/remote_pipes/remote_pipes_validators.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:dartz/dartz.dart'; - -Either, String> validateRemotePipesEmpty( - String input, -) { - if (input.isNotEmpty) { - return right(input); - } else { - return left( - RemotePipesFailures.empty( - failedValue: input, - ), - ); - } -} diff --git a/lib/domain/remote_pipes/remote_pipes_value_objects.dart b/lib/domain/remote_pipes/remote_pipes_value_objects.dart deleted file mode 100644 index 2110155c9..000000000 --- a/lib/domain/remote_pipes/remote_pipes_value_objects.dart +++ /dev/null @@ -1,50 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_errors.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_validators.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/foundation.dart'; - -@immutable -abstract class RemotePipesValueObjectAbstract { - const RemotePipesValueObjectAbstract(); - - Either, T> get value; - - /// Throws [UnexpectedValueError] containing the [ManageWiFiFailures] - T getOrCrash() { - // id = identity - same as writing (right) => right - return value.fold((f) => throw RemotePipesUnexpectedValueError(f), id); - } - - Either, Unit> get failureOrUnit { - return value.fold((l) => left(l), (r) => right(unit)); - } - - bool isValid() => value.isRight(); - - @override - String toString() => 'Value($value)'; - - @override - @nonVirtual - bool operator ==(Object o) { - if (identical(this, o)) return true; - return o is RemotePipesValueObjectAbstract && o.value == value; - } - - @override - int get hashCode => value.hashCode; -} - -class RemotePipesDomain extends RemotePipesValueObjectAbstract { - factory RemotePipesDomain(String input) { - return RemotePipesDomain._( - validateRemotePipesEmpty(input), - ); - } - - const RemotePipesDomain._(this.value); - - @override - final Either, String> value; -} diff --git a/lib/infrastructure/create_home/create_home_dtos.dart b/lib/infrastructure/create_home/create_home_dtos.dart deleted file mode 100644 index d58ef7ba3..000000000 --- a/lib/infrastructure/create_home/create_home_dtos.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:cybear_jinni/domain/create_home/create_home_entity.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'create_home_dtos.freezed.dart'; -part 'create_home_dtos.g.dart'; - -@freezed -abstract class CreateHomeDtos implements _$CreateHomeDtos { - const factory CreateHomeDtos({ - required String homeDevicesUserId, - required String homeDevicesUserEmail, - required String homeDevicesUserPassword, - @JsonKey(includeFromJson: true) String? id, - @JsonKey(includeFromJson: true) String? name, - // required @ServerTimestampConverter() FieldValue serverTimeStamp, - }) = _CreateHomeDtos; - - const CreateHomeDtos._(); - - factory CreateHomeDtos.fromJson(Map json) => - _$CreateHomeDtosFromJson(json); - - factory CreateHomeDtos.fromDomain(CreateHomeEntity createHomeEntity) { - return CreateHomeDtos( - homeDevicesUserId: createHomeEntity.homeDevicesUserId!.getOrCrash(), - homeDevicesUserEmail: createHomeEntity.homeDevicesUserEmail!.getOrCrash(), - homeDevicesUserPassword: - createHomeEntity.homeDevicesUserPassword!.getOrCrash(), - // serverTimeStamp: FieldValue.serverTimestamp(), - ); - } - - CreateHomeEntity toDomain() { - return CreateHomeEntity( - name: HomeName(' '), - id: HomeUniqueId.fromUniqueString(' '), - homeDevicesUserId: HomeDevicesUserId(), - homeDevicesUserEmail: HomeDevicesUserEmail(homeDevicesUserEmail), - homeDevicesUserPassword: - HomeDevicesUserPassword.fromUniqueString(homeDevicesUserPassword), - ); - } -} - -// class ServerTimestampConverter implements JsonConverter { -// const ServerTimestampConverter(); -// -// @override -// FieldValue fromJson(Object json) { -// return FieldValue.serverTimestamp(); -// } -// -// @override -// Object toJson(FieldValue fieldValue) => fieldValue; -// } diff --git a/lib/infrastructure/create_home/create_home_repository.dart b/lib/infrastructure/create_home/create_home_repository.dart deleted file mode 100644 index 14df9a2ae..000000000 --- a/lib/infrastructure/create_home/create_home_repository.dart +++ /dev/null @@ -1,239 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/i_add_user_to_home_repository.dart'; -import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; -import 'package:cybear_jinni/domain/auth/user.dart'; -import 'package:cybear_jinni/domain/auth/value_objects.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_entity.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_failure.dart'; -import 'package:cybear_jinni/domain/create_home/create_home_value_objects.dart'; -import 'package:cybear_jinni/domain/create_home/i_create_home_repository.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_value_objects.dart'; -import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_value_objects.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/domain/user/user_errors.dart'; -import 'package:cybear_jinni/domain/user/user_failures.dart'; -import 'package:cybear_jinni/infrastructure/create_home/create_home_dtos.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/services.dart'; - -class CreateHomeRepository implements ICreateHomeRepository { - final String smartHomesPath = 'SmartHomes'; - final String usersInHomePath = 'Users'; - - @override - Future> createNewHome( - CreateHomeEntity? createHomeEntity, - ) async { - try { - if (createHomeEntity!.homeDevicesUserEmail!.getOrCrash().isEmpty) { - return left(const CreateHomeFailure.devicesUserEmailIsInvalid()); - } - - CreateHomeEntity createHomeEntityWithId = - createHomeEntity.copyWith(id: HomeUniqueId()); - - final UserEntity userEntity = - (await IUserRepository.instance.getCurrentUser()).getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - // Create user for devices - final registerDeviceUser = - await IAuthFacade.instance.registerWithEmailAndPasswordReturnUserId( - emailAddress: EmailAddress( - createHomeEntityWithId.homeDevicesUserEmail!.getOrCrash(), - ), - password: Password( - createHomeEntityWithId.homeDevicesUserPassword!.getOrCrash(), - ), - ); - final MUser deviceUserId = registerDeviceUser.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - createHomeEntityWithId = createHomeEntityWithId.copyWith( - homeDevicesUserId: HomeDevicesUserId.fromUniqueString( - deviceUserId.id.getOrCrash(), - ), - ); - - // create home with the current user - await ILocalDbRepository2.instance - .setHomeId(createHomeEntityWithId.id.getOrCrash()); - - final creatingHomeWithUser = await addUserToHome(userEntity); - - creatingHomeWithUser.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - // Add the home its info like name - - final addHomeInfoRes = await addHomeInfo(createHomeEntityWithId); - - addHomeInfoRes.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - // Add the devices user info to home - final saveDeviceAccountToHome = - await addDeviceUserToHome(createHomeEntityWithId); - - saveDeviceAccountToHome.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - // Add home to user homes list - final addingHomeToUserHomesList = - await addHomeToUserHomesList(userEntity, createHomeEntityWithId); - - addingHomeToUserHomesList.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - return right(unit); - } catch (e) { - return left(CreateHomeFailure.unexpected(failedValue: e.toString())); - } - } - - Future> addHomeToUserHomesList( - UserEntity userEntity, - CreateHomeEntity createHomeEntity, - ) async { - try { - final String homeId = createHomeEntity.id.getOrCrash(); - final String homeName = createHomeEntity.name.getOrCrash(); - final AllHomesOfUserEntity allHomesOfUserEntity = AllHomesOfUserEntity( - id: AllHomesOfUserUniqueId.fromUniqueString(homeId), - name: AllHomesOfUserName(homeName), - ); - final addHomeToUserHomesList = await IUserRepository.instance - .addHome(userEntity, allHomesOfUserEntity); - - addHomeToUserHomesList.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - - return right(unit); - } catch (e) { - return left( - const CreateHomeFailure.unexpected( - failedValue: 'Failure adding home to user homes list', - ), - ); - } - } - - @override - Future> addDeviceUserToHome( - CreateHomeEntity createHomeEntity, - ) async { - try { - CreateHomeDtos.fromDomain(createHomeEntity); - - // await homeDoc.devicesUsersCollecttion - // .doc('default') - // .set(deviceHomeUserDtos.toJson()); - return right(unit); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const CreateHomeFailure.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(CreateHomeFailure.unexpected(failedValue: e.message)); - } - } - } - - @override - Future> getDeviceUserFromHome() async { - try { - // return right(userEntity); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const CreateHomeFailure.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(CreateHomeFailure.unexpected(failedValue: e.message)); - } - } catch (error) { - return left(CreateHomeFailure.unexpected(failedValue: error.toString())); - } - return left( - const CreateHomeFailure.unexpected(failedValue: 'Not implemented yet'), - ); - } - - Future> addHomeInfo( - CreateHomeEntity createHomeEntity, - ) async { - try { - return right(unit); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const CreateHomeFailure.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(CreateHomeFailure.unexpected(failedValue: e.message)); - } - } - } - - @override - Future> getFirstWifi() async { - try { - return right( - ManageNetworkEntity( - name: ManageWiFiName('CyBear Jinni'), - pass: ManageWiFiPass('CyBear Jinni'), - ), - ); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const CreateHomeFailure.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(CreateHomeFailure.unexpected(failedValue: e.message)); - } - } catch (error) { - return left(CreateHomeFailure.unexpected(failedValue: error.toString())); - } - } - - @override - Future> addUserToHome( - UserEntity userEntity, - ) async { - try { - final String currentUserUid = userEntity.id!.getOrCrash()!; - final String currentUserEmail = userEntity.email!.getOrCrash(); - final String currentUserName = userEntity.name!.getOrCrash(); - - final HomeUserEntity homeUserEntity = HomeUserEntity( - id: HomeUserUniqueId.fromUniqueString(currentUserUid), - email: HomeUserEmail(currentUserEmail), - name: HomeUserName(currentUserName), - permission: HomeUserPermission('admin'), - ); - - final Either createHome = - await IAddUserToHomeRepository.instance.create(homeUserEntity); - createHome.getOrElse( - () => throw UserUnexpectedValueError(const UserFailures.unexpected()), - ); - return right(unit); - } catch (e) { - return left( - const CreateHomeFailure.unexpected( - failedValue: 'Failure addUserToHome', - ), - ); - } - } -} diff --git a/lib/infrastructure/hub_client/hub_requests_routing.dart b/lib/infrastructure/hub_client/hub_requests_routing.dart index 5e09daee1..d3339079f 100644 --- a/lib/infrastructure/hub_client/hub_requests_routing.dart +++ b/lib/infrastructure/hub_client/hub_requests_routing.dart @@ -31,8 +31,7 @@ import 'package:cybear_jinni/utils.dart'; import 'package:grpc/grpc.dart'; class HubRequestRouting { - static StreamSubscription? - requestsFromHubSubscription; + static StreamSubscription? requestsFromHubSubscription; static Stream? connectivityChangedStream; @@ -75,7 +74,7 @@ class HubRequestRouting { '${requestsAndStatusFromHub.sendingType}', ); } - }) as StreamSubscription?; + }); requestsFromHubSubscription?.onError((error) async { if (error is GrpcError && error.code == 1) { logger.t('Hub have been disconnected'); diff --git a/lib/infrastructure/remote_pipes/remote_pipes_dtos.dart b/lib/infrastructure/remote_pipes/remote_pipes_dtos.dart deleted file mode 100644 index 0544f6f7f..000000000 --- a/lib/infrastructure/remote_pipes/remote_pipes_dtos.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'remote_pipes_dtos.freezed.dart'; -part 'remote_pipes_dtos.g.dart'; - -@freezed -abstract class RemotePipesDtos implements _$RemotePipesDtos { - factory RemotePipesDtos({ - // @JsonKey(includeFromJson: true) - required String domainName, - // required ServerTimestampConverter() FieldValue serverTimeStamp, - }) = _RemotePipesDtos; - - RemotePipesDtos._(); - - factory RemotePipesDtos.fromDomain(RemotePipesEntity remotePipesDE) { - return RemotePipesDtos( - domainName: remotePipesDE.domainName!.getOrCrash(), - // serverTimeStamp: FieldValue.serverTimestamp(), - ); - } - - factory RemotePipesDtos.fromJson(Map json) => - _$RemotePipesDtosFromJson(json); - - final String deviceDtoClassInstance = (RemotePipesDtos).toString(); - - RemotePipesEntity toDomain() { - return RemotePipesEntity( - domainName: RemotePipesDomain(domainName), - ); - } -} - -// class ServerTimestampConverter implements JsonConverter { -// const ServerTimestampConverter(); -// -// @override -// FieldValue fromJson(Object json) { -// return FieldValue.serverTimestamp(); -// } -// -// @override -// Object toJson(FieldValue fieldValue) => fieldValue; -// } diff --git a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart b/lib/infrastructure/remote_pipes/remote_pipes_repository.dart deleted file mode 100644 index 523c65d09..000000000 --- a/lib/infrastructure/remote_pipes/remote_pipes_repository.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:convert'; - -import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; -import 'package:cybear_jinni/domain/remote_pipes/i_remote_pipes_repository.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_entity.dart'; -import 'package:cybear_jinni/domain/remote_pipes/remote_pipes_failures.dart'; -import 'package:cybear_jinni/infrastructure/remote_pipes/remote_pipes_dtos.dart'; -import 'package:dartz/dartz.dart'; - -class RemotePipesRepository implements IRemotePipesRepository { - @override - Future> setRemotePipesDomainName( - RemotePipesEntity remotePipesEntity, - ) async { - try { - final RemotePipesDtos remotePipesDtos = - remotePipesEntity.toInfrastructure(); - final String remotePipesDtosAsJson = jsonEncode(remotePipesDtos.toJson()); - - final ClientStatusRequests clientStatusRequests = ClientStatusRequests( - allRemoteCommands: remotePipesDtosAsJson, - sendingType: SendingType.remotePipesInformation, - ); - - AppRequestsToHub.appRequestsToHubStreamController - .add(clientStatusRequests); - - ILocalDbRepository.instance - .saveRemotePipes(remotePipesDomainName: remotePipesDtos.domainName); - - return right(unit); - } catch (e) { - return left(const RemotePipesFailures.unexpected()); - } - } -} diff --git a/lib/presentation/pages/add_new_automation_process/add_action/add_action_page.dart b/lib/presentation/pages/add_new_automation_process/add_action/add_action_page.dart index 5b29b9dcd..991cf9d5c 100644 --- a/lib/presentation/pages/add_new_automation_process/add_action/add_action_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_action/add_action_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_new_action/add_new_action_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -33,10 +30,7 @@ class AddActionPage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - BlocProvider( - create: (context) => getIt(), - child: ActionChooseInformation(), - ), + ActionChooseInformation(), ], ), ); diff --git a/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart b/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart index cddf40205..a487b0635 100644 --- a/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart +++ b/lib/presentation/pages/add_new_automation_process/add_action/widgets/action_choose_information.dart @@ -1,181 +1,259 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/add_new_action/add_new_action_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:hexcolor/hexcolor.dart'; -class ActionChooseInformation extends StatelessWidget { +class ActionChooseInformation extends StatefulWidget { + @override + State createState() => + _ActionChooseInformationState(); +} + +class _ActionChooseInformationState extends State { + List _allRooms = []; + List _allDevices = []; + + String actionsName = ''; + String propertyName = ''; + + /// Will contain (in that order) device to change his property to change and the new value of this property + List>> + allDevicesWithNewAction = []; + List> allEntityActions = []; + bool isSubmitting = false; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + List allRoomsTemp = []; + (await IRoomRepository.instance.getAllRooms()).fold((l) => null, (r) { + allRoomsTemp = List.from(r.iter); + }); + allRoomsTemp.removeWhere((element) => element == null); + + List allDevicesTemp = []; + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + allDevicesTemp = List.from(r.iter); + }); + allDevicesTemp.removeWhere((element) => element == null); + setState(() { + _allRooms = allRoomsTemp.map((e) => e!).toList(); + _allDevices = allDevicesTemp.map((e) => e!).toList(); + }); + } + + Future _changeActionDevices(String actionForProperty) async { + for (final DeviceEntityAbstract? device in _allDevices) { + if (device != null && actionForProperty == device.uniqueId.getOrCrash()) { + setState(() { + allDevicesWithNewAction = [ + MapEntry(device, const MapEntry(null, null)), + ]; + actionsName = ''; + }); + } + } + } + + Future _actionsNameChange(String value) async { + if (allDevicesWithNewAction.isNotEmpty) { + final List>> + tempAllDevicesWithNewActionList = List.from(allDevicesWithNewAction); + + final MapEntry propertyWithAction = MapEntry( + tempAllDevicesWithNewActionList[0].value.key, + actionsName, + ); + + tempAllDevicesWithNewActionList[0] = + MapEntry(tempAllDevicesWithNewActionList[0].key, propertyWithAction); + + setState(() { + actionsName = value; + allDevicesWithNewAction = tempAllDevicesWithNewActionList; + }); + } + } + + Future _changePropertyForDevices(String propertyOfDevice) async { + if (allDevicesWithNewAction.isNotEmpty) { + final List>> + tempAllDevicesWithNewActionList = List.from(allDevicesWithNewAction); + + final MapEntry propertyWithAction = MapEntry( + propertyOfDevice, + null, + ); + + tempAllDevicesWithNewActionList[0] = + MapEntry(tempAllDevicesWithNewActionList[0].key, propertyWithAction); + + setState(() { + propertyName = propertyOfDevice; + allDevicesWithNewAction = tempAllDevicesWithNewActionList; + }); + } + } + @override Widget build(BuildContext context) { - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return SingleChildScrollView( - child: Container( - color: HexColor('#3A3A3A'), - margin: const EdgeInsets.symmetric(horizontal: 10), - child: Column( + if (_allDevices.isEmpty || _allRooms.isEmpty) { + return const CircularProgressIndicatorAtom(); + } + + return SingleChildScrollView( + child: Container( + color: HexColor('#3A3A3A'), + margin: const EdgeInsets.symmetric(horizontal: 10), + child: Column( + children: [ + const SizedBox( + height: 30, + ), + const SizedBox( + height: 70, + ), + const Row( children: [ - const SizedBox( - height: 30, - ), - const SizedBox( - height: 70, + TextAtom( + 'Choose Action', + style: TextStyle(fontSize: 27), ), - 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( - state.allDevicesWithNewAction.isNotEmpty - ? state.allDevicesWithNewAction[0].key.cbjEntityName - .getOrCrash()! - : 'Choose Device', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) { - context - .read() - .add(AddNewActionEvent.changeActionDevices(value!)); - }, - items: state.allDevices.map>((e) { - return DropdownMenuItem( - value: e.uniqueId.getOrCrash(), - child: TextAtom(e.cbjEntityName.getOrCrash()!), + ], + ), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + allDevicesWithNewAction.isNotEmpty + ? allDevicesWithNewAction[0].key.cbjEntityName.getOrCrash()! + : 'Choose Device', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => _changeActionDevices(value!), + items: _allDevices.map>((e) { + return DropdownMenuItem( + value: e.uniqueId.getOrCrash(), + 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( + propertyName != '' ? propertyName : 'Property to change', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => _changePropertyForDevices(value!), + items: allDevicesWithNewAction.isNotEmpty + ? allDevicesWithNewAction[0] + .key + .getListOfPropertiesToChange() + .map>((e) { + return DropdownMenuItem( + value: e, + child: TextAtom(e), + ); + }).toList() + : >[ + const DropdownMenuItem( + value: 'Choose device first', + child: TextAtom('Choose device first'), + ), + ], + ), + const SizedBox( + height: 40, + ), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + actionsName != '' ? actionsName : 'Choose Action', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => _actionsNameChange(value!), + items: (allDevicesWithNewAction.isNotEmpty && + allDevicesWithNewAction[0].value.key != null && + allDevicesWithNewAction[0].value.key!.isNotEmpty) + ? allDevicesWithNewAction[0] + .key + .getAllValidActions() + .map>((e) { + return DropdownMenuItem( + value: e, + child: TextAtom(e), + ); + }).toList() + : >[ + const DropdownMenuItem( + value: 'Choose property first', + child: TextAtom('Choose property first'), + ), + ], + ), + const SizedBox( + height: 70, + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Add action', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.purple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + + context.router.pop< + List< + MapEntry>>>( + allDevicesWithNewAction, ); - }).toList(), - ), - const SizedBox( - height: 40, - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - state.propertyName != '' - ? state.propertyName - : 'Property to change', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) { - context.read().add( - AddNewActionEvent.changePropertyForDevices(value!), - ); }, - items: state.allDevicesWithNewAction.isNotEmpty - ? state.allDevicesWithNewAction[0].key - .getListOfPropertiesToChange() - .map>((e) { - return DropdownMenuItem( - value: e, - child: TextAtom(e), - ); - }).toList() - : >[ - const DropdownMenuItem( - value: 'Choose device first', - child: TextAtom('Choose device first'), - ), - ], - ), - const SizedBox( - height: 40, - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - state.actionsName != '' - ? state.actionsName - : 'Choose Action', - style: const TextStyle(color: Colors.white), + child: const TextAtom( + 'Done', + style: TextStyle(fontSize: 20), ), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) { - context - .read() - .add(AddNewActionEvent.actionsNameChange(value!)); - }, - items: (state.allDevicesWithNewAction.isNotEmpty && - state.allDevicesWithNewAction[0].value.key != null && - state - .allDevicesWithNewAction[0].value.key!.isNotEmpty) - ? state.allDevicesWithNewAction[0].key - .getAllValidActions() - .map>((e) { - return DropdownMenuItem( - value: e, - child: TextAtom(e), - ); - }).toList() - : >[ - const DropdownMenuItem( - value: 'Choose property first', - child: TextAtom('Choose property first'), - ), - ], - ), - const SizedBox( - height: 70, - ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () { - Fluttertoast.showToast( - msg: 'Add action', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.purple, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - - context.router.pop< - List< - MapEntry>>>( - state.allDevicesWithNewAction, - ); - }, - child: const TextAtom( - 'Done', - style: TextStyle(fontSize: 20), - ), - ), - ], ), ], ), - ), - ); - }, + ], + ), + ), ); } } diff --git a/lib/presentation/pages/add_new_automation_process/add_bindings/add_binding_page.dart b/lib/presentation/pages/add_new_automation_process/add_bindings/add_binding_page.dart index 1063e1fa2..43d9af4a2 100644 --- a/lib/presentation/pages/add_new_automation_process/add_bindings/add_binding_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_bindings/add_binding_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_new_binding/add_new_binding_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -35,10 +32,7 @@ class AddBindingPage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - BlocProvider( - create: (context) => getIt(), - child: AddBindingWidget(), - ), + AddBindingWidget(), ], ), ), diff --git a/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart b/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart index f5c16a762..2f3b19947 100644 --- a/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_bindings/widgets/add_binding_widget.dart @@ -1,193 +1,224 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/binding/i_binding_cbj_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/add_new_binding/add_new_binding_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_bindings/widgets/binding_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class AddBindingWidget extends StatelessWidget { +class AddBindingWidget extends StatefulWidget { + @override + State createState() => _AddBindingWidgetState(); +} + +class _AddBindingWidgetState extends State { + List _allDevices = []; + + String bindingName = ''; + + /// List of devices with entities, will be treated as actions + List>> + allDevicesWithNewAction = []; + List> allEntityActions = []; + bool showErrorMessages = false; + bool isSubmitting = false; + dartz.Option> + authFailureOrSuccessOption = dartz.none(); + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + List value = []; + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + value = List.from(r.iter); + }); + value.removeWhere((element) => element == null); + + setState(() { + _allDevices = value.map((e) => e!).toList(); + }); + } + + Future _sendBindingToHub() async { + IBindingCbjRepository.instance + .addOrUpdateNewBindingInHubFromDevicesPropertyActionList( + bindingName, + allDevicesWithNewAction, + ); + } + + Future _addDevicesWithNewActions( + List>> value, + ) async { + setState(() { + allDevicesWithNewAction.addAll(value); + }); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => const TextAtom('Initial'), - loadPageState: (loadPageState) { - return Container( - margin: const EdgeInsets.symmetric(horizontal: 20), - child: Column( - children: [ - const SizedBox( - height: 30, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), - labelText: 'Binding Name', - ), - onChanged: (value) { - context.read().add( - AddNewBindingEvent.bindingNameChange( - value, - ), - ); - }, - ), - SizedBox( - height: 300, - width: 500, - child: ListView.builder( - itemCount: loadPageState.allDevicesWithNewAction.length, - itemBuilder: (BuildContext context, int index) { - final MapEntry> currentDevice = - loadPageState.allDevicesWithNewAction[index]; + if (_allDevices.isEmpty) { + return const CircularProgressIndicatorAtom(); + } - return Container( - margin: const EdgeInsets.symmetric(vertical: 1), - child: BindingActionWidget( - deviceEntityAbstract: currentDevice.key, - propertyToChange: - currentDevice.value.key ?? 'Missing property', - actionToChange: currentDevice.value.value ?? - EntityActions.actionNotSupported.toString(), - ), + return Container( + margin: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + children: [ + const SizedBox( + height: 30, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), + labelText: 'Binding Name', + ), + onChanged: (value) { + bindingName = value; + }, + ), + SizedBox( + height: 300, + width: 500, + child: ListView.builder( + itemCount: allDevicesWithNewAction.length, + itemBuilder: (BuildContext context, int index) { + final MapEntry> + currentDevice = allDevicesWithNewAction[index]; + + return Container( + margin: const EdgeInsets.symmetric(vertical: 1), + child: BindingActionWidget( + deviceEntityAbstract: currentDevice.key, + propertyToChange: + currentDevice.value.key ?? 'Missing property', + actionToChange: currentDevice.value.value ?? + EntityActions.actionNotSupported.toString(), + ), + ); + }, + ), + ), + const SizedBox(height: 30), + Container( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + showAdaptiveActionSheet( + context: context, + actions: [ + BottomSheetAction( + title: const TextAtom( + 'Add device action', + style: TextStyle( + color: Colors.blueGrey, + fontSize: 23, + ), + ), + onPressed: (_) async { + final List< + MapEntry>>? actionList = + await context.router.push< + List< + MapEntry>>>( + const AddActionRoute(), ); + if (actionList != null) { + _addDevicesWithNewActions( + actionList, + ); + } }, ), - ), - const SizedBox(height: 30), - Container( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), - ), - child: TextButton( - onPressed: () { - showAdaptiveActionSheet( - context: context, - actions: [ - BottomSheetAction( - title: const TextAtom( - 'Add device action', - style: TextStyle( - color: Colors.blueGrey, - fontSize: 23, - ), - ), - onPressed: (_) async { - final List< - MapEntry>>? - actionList = await context.router.push< - List< - MapEntry>>>( - const AddActionRoute(), - ); - if (actionList != null) { - context.read().add( - AddNewBindingEvent - .addDevicesWithNewActions( - actionList, - ), - ); - } - }, - ), - BottomSheetAction( - title: TextAtom( - 'Add service action', - style: TextStyle( - color: Colors.green.shade600, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding service action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - BottomSheetAction( - title: const TextAtom( - 'Add time based action', - style: TextStyle( - color: Colors.blue, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding time based action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - ], + BottomSheetAction( + title: TextAtom( + 'Add service action', + style: TextStyle( + color: Colors.green.shade600, + fontSize: 23, + ), + ), + onPressed: (_) { + Fluttertoast.showToast( + msg: + 'Adding service action will be added in the future', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: + Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, ); }, - child: const TextAtom('+ Add action'), - ), - ), - const SizedBox(height: 10), - Container( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), ), - child: TextButton( - onPressed: () { + BottomSheetAction( + title: const TextAtom( + 'Add time based action', + style: TextStyle( + color: Colors.blue, + fontSize: 23, + ), + ), + onPressed: (_) { Fluttertoast.showToast( - msg: 'Adding Binding', - toastLength: Toast.LENGTH_SHORT, + msg: + 'Adding time based action will be added in the future', + toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.CENTER, backgroundColor: Colors.blueGrey, textColor: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16.0, ); - context.read().add( - const AddNewBindingEvent.sendBindingToHub(), - ); }, - child: const TextAtom('Add Binding'), ), - ), - ], - ), - ); - }, - loadInProgress: (loadInProgress) { - return const TextAtom('loadInProgress'); - }, - ); - }, + ], + ); + }, + child: const TextAtom('+ Add action'), + ), + ), + const SizedBox(height: 10), + Container( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Adding Binding', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _sendBindingToHub(); + }, + child: const TextAtom('Add Binding'), + ), + ), + ], + ), ); } } diff --git a/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart b/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart index 002185abd..6efacf71d 100644 --- a/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_routine/add_routine_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/routine/value_objects_routine_cbj.dart'; -import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -46,17 +43,7 @@ class AddRoutinePage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - BlocProvider( - create: (context) => getIt() - ..add( - AddNewRoutineEvent.addRoutineDate( - daysToRepeat: daysToRepeat, - hourToRepeat: hourToRepeat, - minutesToRepeat: minutesToRepeat, - ), - ), - child: AddRoutineWidget(), - ), + AddRoutineWidget(), ], ), ), diff --git a/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart b/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart index 721511f30..b2bf337b5 100644 --- a/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_routine/widgets/add_routine_widget.dart @@ -1,196 +1,239 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/routine/i_routine_cbj_repository.dart'; +import 'package:cbj_integrations_controller/domain/routine/value_objects_routine_cbj.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/add_new_routine/add_new_routine_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_routine/widgets/routine_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class AddRoutineWidget extends StatelessWidget { +class AddRoutineWidget extends StatefulWidget { + @override + State createState() => _AddRoutineWidgetState(); +} + +class _AddRoutineWidgetState extends State { + List _allDevices = []; + + String? routineName; + + RoutineCbjRepeatDateDays? daysToRepeat; + RoutineCbjRepeatDateHour? hourToRepeat; + RoutineCbjRepeatDateMinute? minutesToRepeat; + + /// List of devices with entities, will be treated as actions + List>> + allDevicesWithNewAction = []; + List> allEntityActions = []; + bool showErrorMessages = false; + bool isSubmitting = false; + dartz.Option> + authFailureOrSuccessOption = dartz.none(); + + @override + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + List temp = []; + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + temp = List.from(r.iter); + }); + temp.removeWhere((element) => element == null); + + setState(() { + _allDevices = temp.map((e) => e!).toList(); + }); + } + + Future _sendRoutineToHub() async { + if (daysToRepeat == null || + hourToRepeat == null || + minutesToRepeat == null || + routineName == null) { + return; + } + IRoutineCbjRepository.instance + .addOrUpdateNewRoutineInHubFromDevicesPropertyActionList( + routineName!, + allDevicesWithNewAction, + daysToRepeat!, + hourToRepeat!, + minutesToRepeat!, + ); + } + + Future _routineNameChange(String value) async { + routineName = value; + } + + Future _addDevicesWithNewActions( + Iterable>> value, + ) async { + setState(() { + allDevicesWithNewAction.addAll(value); + }); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => const TextAtom('Initial'), - loadPageState: (loadPageState) { - return Container( - margin: const EdgeInsets.symmetric(horizontal: 20), - child: Column( - children: [ - const SizedBox( - height: 30, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), - labelText: 'Routine Name', - ), - onChanged: (value) { - context.read().add( - AddNewRoutineEvent.routineNameChange( - value, - ), - ); - }, - ), - SizedBox( - height: 300, - width: 500, - child: ListView.builder( - itemCount: loadPageState.allDevicesWithNewAction.length, - itemBuilder: (BuildContext context, int index) { - final MapEntry> currentDevice = - loadPageState.allDevicesWithNewAction[index]; + if (_allDevices.isNotEmpty) { + return const CircularProgressIndicatorAtom(); + } - return Container( - margin: const EdgeInsets.symmetric(vertical: 1), - child: RoutineActionWidget( - deviceEntityAbstract: currentDevice.key, - propertyToChange: - currentDevice.value.key ?? 'Missing property', - actionToChange: currentDevice.value.value ?? - EntityActions.actionNotSupported.toString(), - ), + return Container( + margin: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + children: [ + const SizedBox( + height: 30, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), + labelText: 'Routine Name', + ), + onChanged: _routineNameChange, + ), + SizedBox( + height: 300, + width: 500, + child: ListView.builder( + itemCount: allDevicesWithNewAction.length, + itemBuilder: (BuildContext context, int index) { + final MapEntry> + currentDevice = allDevicesWithNewAction[index]; + + return Container( + margin: const EdgeInsets.symmetric(vertical: 1), + child: RoutineActionWidget( + deviceEntityAbstract: currentDevice.key, + propertyToChange: + currentDevice.value.key ?? 'Missing property', + actionToChange: currentDevice.value.value ?? + EntityActions.actionNotSupported.toString(), + ), + ); + }, + ), + ), + const SizedBox(height: 30), + Container( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + showAdaptiveActionSheet( + context: context, + actions: [ + BottomSheetAction( + title: const TextAtom( + 'Add device action', + style: TextStyle( + color: Colors.blueGrey, + fontSize: 23, + ), + ), + onPressed: (_) async { + final List< + MapEntry>>? actionList = + await context.router.push< + List< + MapEntry>>>( + const AddActionRoute(), ); + if (actionList != null) { + _addDevicesWithNewActions(actionList); + } }, ), - ), - const SizedBox(height: 30), - Container( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), - ), - child: TextButton( - onPressed: () { - showAdaptiveActionSheet( - context: context, - actions: [ - BottomSheetAction( - title: const TextAtom( - 'Add device action', - style: TextStyle( - color: Colors.blueGrey, - fontSize: 23, - ), - ), - onPressed: (_) async { - final List< - MapEntry>>? - actionList = await context.router.push< - List< - MapEntry>>>( - const AddActionRoute(), - ); - if (actionList != null) { - context.read().add( - AddNewRoutineEvent - .addDevicesWithNewActions( - actionList, - ), - ); - } - }, - ), - BottomSheetAction( - title: TextAtom( - 'Add service action', - style: TextStyle( - color: Colors.green.shade600, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding service action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - BottomSheetAction( - title: const TextAtom( - 'Add time based action', - style: TextStyle( - color: Colors.blue, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding time based action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - ], + BottomSheetAction( + title: TextAtom( + 'Add service action', + style: TextStyle( + color: Colors.green.shade600, + fontSize: 23, + ), + ), + onPressed: (_) { + Fluttertoast.showToast( + msg: + 'Adding service action will be added in the future', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: + Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, ); }, - child: const TextAtom('+ Add action'), - ), - ), - const SizedBox(height: 10), - Container( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), ), - child: TextButton( - onPressed: () { + BottomSheetAction( + title: const TextAtom( + 'Add time based action', + style: TextStyle( + color: Colors.blue, + fontSize: 23, + ), + ), + onPressed: (_) { Fluttertoast.showToast( - msg: 'Adding Routine', - toastLength: Toast.LENGTH_SHORT, + msg: + 'Adding time based action will be added in the future', + toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.CENTER, backgroundColor: Colors.blueGrey, textColor: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16.0, ); - context.read().add( - const AddNewRoutineEvent.sendRoutineToHub(), - ); }, - child: const TextAtom('Add Routine'), ), - ), - ], - ), - ); - }, - loadInProgress: (loadInProgress) { - return const TextAtom('load In Progress'); - }, - addNewRoutineFailure: (AddNewRoutineFailure value) { - return const TextAtom('Failure while adding new routine'); - }, - ); - }, + ], + ); + }, + child: const TextAtom('+ Add action'), + ), + ), + const SizedBox(height: 10), + Container( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Adding Routine', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _sendRoutineToHub(); + }, + child: const TextAtom('Add Routine'), + ), + ), + ], + ), ); } } diff --git a/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart b/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart index 66a1ee1ce..47e8bca24 100644 --- a/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/add_new_scene/add_new_scene_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -35,10 +32,7 @@ class AddScenePage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - BlocProvider( - create: (context) => getIt(), - child: AddSceneWidget(), - ), + AddSceneWidget() ], ), ), diff --git a/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart b/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart index 94568b13c..3ad55991d 100644 --- a/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart +++ b/lib/presentation/pages/add_new_automation_process/add_scene/widgets/add_scene_widget.dart @@ -1,193 +1,238 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; +import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/add_new_scene/add_new_scene_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_automation_process/add_scene/widgets/scene_action_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class AddSceneWidget extends StatelessWidget { +class AddSceneWidget extends StatefulWidget { + @override + State createState() => _AddSceneWidgetState(); +} + +class _AddSceneWidgetState extends State { + String sceneName = ''; + List allDevices = []; + + /// List of devices with entities, will be treated as actions + List>> + allDevicesWithNewAction = []; + List> allEntityActions = []; + bool showErrorMessages = false; + bool isSubmitting = false; + dartz.Option> + authFailureOrSuccessOption = dartz.none(); + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + List allDevicesTemp = []; + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + allDevicesTemp = List.from(r.iter); + }); + + allDevicesTemp.removeWhere((element) => element == null); + setState(() { + allDevices = allDevicesTemp.map((e) => e!).toList(); + }); + } + + Future _sendSceneToHub() async { + ISceneCbjRepository.instance + .addOrUpdateNewSceneInHubFromDevicesPropertyActionList( + sceneName, + allDevicesWithNewAction, + // TODO: Check what value to use + AreaPurposesTypes.laundryRoom, + ); + } + + Future _sceneNameChange(String value) async { + sceneName = value; + } + + Future _addDevicesWithNewActions( + List>> value, + ) async { + setState(() { + allDevicesWithNewAction.addAll(value); + }); + } + + // List>> + // smartDevicesWithActionToAdd, + // required String actionsName, + // required List allDevices, + // required List>> + // allDevicesWithNewAction, + // required List> allEntityActions, + // required bool showErrorMessages, + // required bool isSubmitting, + // required Option> authFailureOrSuccessOption, + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => const TextAtom('Initial'), - loadPageState: (loadPageState) { - return Container( - margin: const EdgeInsets.symmetric(horizontal: 20), - child: Column( - children: [ - const SizedBox( - height: 30, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), - labelText: 'Scene Name', - ), - onChanged: (value) { - context.read().add( - AddNewSceneEvent.sceneNameChange( - value, - ), - ); - }, - ), - SizedBox( - height: 300, - width: 500, - child: ListView.builder( - itemCount: loadPageState.allDevicesWithNewAction.length, - itemBuilder: (BuildContext context, int index) { - final MapEntry> currentDevice = - loadPageState.allDevicesWithNewAction[index]; + if (allEntityActions.isNotEmpty) { + return const CircularProgressIndicatorAtom(); + } + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 20), + child: Column( + children: [ + const SizedBox( + height: 30, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), + labelText: 'Scene Name', + ), + onChanged: _sceneNameChange, + ), + SizedBox( + height: 300, + width: 500, + child: ListView.builder( + itemCount: allDevicesWithNewAction.length, + itemBuilder: (BuildContext context, int index) { + final MapEntry> + currentDevice = allDevicesWithNewAction[index]; - return Container( - margin: const EdgeInsets.symmetric(vertical: 1), - child: SceneActionWidget( - deviceEntityAbstract: currentDevice.key, - propertyToChange: - currentDevice.value.key ?? 'Missing property', - actionToChange: currentDevice.value.value ?? - EntityActions.actionNotSupported.toString(), - ), + return Container( + margin: const EdgeInsets.symmetric(vertical: 1), + child: SceneActionWidget( + deviceEntityAbstract: currentDevice.key, + propertyToChange: + currentDevice.value.key ?? 'Missing property', + actionToChange: currentDevice.value.value ?? + EntityActions.actionNotSupported.toString(), + ), + ); + }, + ), + ), + const SizedBox(height: 30), + DecoratedBox( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + showAdaptiveActionSheet( + context: context, + actions: [ + BottomSheetAction( + title: const TextAtom( + 'Add device action', + style: TextStyle( + color: Colors.blueGrey, + fontSize: 23, + ), + ), + onPressed: (_) async { + final List< + MapEntry>>? actionList = + await context.router.push< + List< + MapEntry>>>( + const AddActionRoute(), ); + if (actionList != null) { + _addDevicesWithNewActions( + actionList, + ); + } }, ), - ), - const SizedBox(height: 30), - DecoratedBox( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), - ), - child: TextButton( - onPressed: () { - showAdaptiveActionSheet( - context: context, - actions: [ - BottomSheetAction( - title: const TextAtom( - 'Add device action', - style: TextStyle( - color: Colors.blueGrey, - fontSize: 23, - ), - ), - onPressed: (_) async { - final List< - MapEntry>>? - actionList = await context.router.push< - List< - MapEntry>>>( - const AddActionRoute(), - ); - if (actionList != null) { - context.read().add( - AddNewSceneEvent - .addDevicesWithNewActions( - actionList, - ), - ); - } - }, - ), - BottomSheetAction( - title: TextAtom( - 'Add service action', - style: TextStyle( - color: Colors.green.shade600, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding service action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - BottomSheetAction( - title: const TextAtom( - 'Add time based action', - style: TextStyle( - color: Colors.blue, - fontSize: 23, - ), - ), - onPressed: (_) { - Fluttertoast.showToast( - msg: - 'Adding time based action will be added in the future', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ); - }, - ), - ], + BottomSheetAction( + title: TextAtom( + 'Add service action', + style: TextStyle( + color: Colors.green.shade600, + fontSize: 23, + ), + ), + onPressed: (_) { + Fluttertoast.showToast( + msg: + 'Adding service action will be added in the future', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: + Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, ); }, - child: const TextAtom('+ Add action'), - ), - ), - const SizedBox(height: 10), - DecoratedBox( - decoration: BoxDecoration( - color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 - border: Border.all(), ), - child: TextButton( - onPressed: () { + BottomSheetAction( + title: const TextAtom( + 'Add time based action', + style: TextStyle( + color: Colors.blue, + fontSize: 23, + ), + ), + onPressed: (_) { Fluttertoast.showToast( - msg: 'Adding Scene', - toastLength: Toast.LENGTH_SHORT, + msg: + 'Adding time based action will be added in the future', + toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.CENTER, backgroundColor: Colors.blueGrey, textColor: Theme.of(context).textTheme.bodyLarge!.color, fontSize: 16.0, ); - context.read().add( - const AddNewSceneEvent.sendSceneToHub(), - ); }, - child: const TextAtom('Add Scene'), ), - ), - ], - ), - ); - }, - loadInProgress: (loadInProgress) { - return const TextAtom('loadInProgress'); - }, - ); - }, + ], + ); + }, + child: const TextAtom('+ Add action'), + ), + ), + const SizedBox(height: 10), + DecoratedBox( + decoration: BoxDecoration( + color: Colors.lightBlueAccent.withOpacity(0.5), + // Red border with the width is equal to 5 + border: Border.all(), + ), + child: TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Adding Scene', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _sendSceneToHub(); + }, + child: const TextAtom('Add Scene'), + ), + ), + ], + ), ); } } diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart index 22ee28f6a..ff609d1e9 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/manage_access_point/manage_access_point_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -70,11 +67,7 @@ class OpenAccessPointPage extends StatelessWidget { height: 20, ), Expanded( - child: BlocProvider( - create: (context) => getIt() - ..add(ManageAccessPointEvent.initialized()), - child: OpenAccessPointWidget(), - ), + child: OpenAccessPointWidget(), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart index d7aaf2cf4..1770aa6e7 100644 --- a/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/open_access_point/widgets/open_access_point_widget.dart @@ -1,203 +1,261 @@ +import 'dart:io'; + import 'package:auto_route/auto_route.dart'; import 'package:clipboard/clipboard.dart'; -import 'package:cybear_jinni/application/manage_access_point/manage_access_point_bloc.dart'; +import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; +import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; -class OpenAccessPointWidget extends StatelessWidget { +class OpenAccessPointWidget extends StatefulWidget { @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return SingleChildScrollView( - child: Column( - children: [ - state.map( - initial: (value) { - return TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.greenAccent, - ), + State createState() => _OpenAccessPointWidgetState(); +} + +class _OpenAccessPointWidgetState extends State { + OpenAccessPointState state = OpenAccessPointState.initial; + + ManageWiFiName? wifiName; + ManageWiFiPass? wifiPassword; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + OpenAccessPointState stateTemp; + if (Platform.isAndroid) { + final ManageNetworkEntity manageNetworkEntity = ManageNetworkEntity( + name: ManageWiFiName('CyBear Jinni'), + pass: ManageWiFiPass('CyBear Jinni'), + ); + + final dartz.Either openedAccessPoint = + await IManageNetworkRepository.instance + .openAccessPoint(manageNetworkEntity); + stateTemp = openedAccessPoint.fold( + (f) => OpenAccessPointState.iOSDevice, + (r) => OpenAccessPointState.loaded, + ); + } else { + stateTemp = OpenAccessPointState.iOSDevice; + } + setState(() { + state = stateTemp; + }); + } + + Future _doesAccessPointOpen() async { + OpenAccessPointState stateTemp; + + if (Platform.isAndroid) { + final dartz.Either openedAccessPoint = + await IManageNetworkRepository.instance.doesAccessPointOpen(); + + stateTemp = openedAccessPoint.fold((HomeUserFailures f) { + if (f == const HomeUserFailures.accessPointIsNotOpen()) { + return OpenAccessPointState.accessPointIsNotOpen; + } + return OpenAccessPointState.cantDetermineAccessPointOpenOrNot; + }, (r) { + context.router.replace(const ScanForNewCBJCompsRoute()); + + return OpenAccessPointState.accessPointIsOpen; + }); + } else { + stateTemp = OpenAccessPointState.cantDetermineAccessPointOpenOrNot; + } + setState(() { + state = stateTemp; + }); + } + + Widget getStateWidget() { + switch (state) { + case OpenAccessPointState.initial: + return TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.greenAccent, + ), + ), + onPressed: _initialized, + child: const TextAtom('Create Access Pint'), + ); + case OpenAccessPointState.loading: + return const CircularProgressIndicatorAtom(); + case OpenAccessPointState.loaded: + return const TextAtom('Loaded'); + case OpenAccessPointState.error: + return const TextAtom('Failure'); + case OpenAccessPointState.iOSDevice: + return Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(horizontal: 50), + child: const TextAtom( + 'Please Open Access point with the following ' + 'credentials in the OS Settings.', + style: TextStyle(fontSize: 17), + ), + ), + const SizedBox( + height: 30, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: SizedBox( + width: double.infinity, + height: 70, + child: TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.black12, ), - onPressed: () { - context - .read() - .add(ManageAccessPointEvent.initialized()); - }, - child: const TextAtom('Create Access Pint'), - ); - }, - loading: (_) { - return const CircularProgressIndicatorAtom(); - }, - loaded: (l) { - // ExtendedNavigator.of(context) - // .push(Routes.openAccessPointPage); - return const TextAtom('Loaded'); - }, - error: (e) { - return const TextAtom('Failure'); - }, - iOSDevice: (IOSDevice value) { - return Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(horizontal: 50), - child: const TextAtom( - 'Please Open Access point with the following ' - 'credentials in the OS Settings.', - style: TextStyle(fontSize: 17), - ), + ), + onPressed: () { + FlutterClipboard.copy('CyBear Jinni').then( + (value) => Fluttertoast.showToast( + msg: 'Copy', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.SNACKBAR, + backgroundColor: Colors.lightBlue, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, ), - const SizedBox( - height: 30, + ); + }, + child: const Column( + children: [ + TextAtom( + 'Hotspot name:', + style: TextStyle(color: Colors.white60), ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: SizedBox( - width: double.infinity, - height: 70, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.black12, - ), - ), - onPressed: () { - FlutterClipboard.copy('CyBear Jinni').then( - (value) => Fluttertoast.showToast( - msg: 'Copy', - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.SNACKBAR, - backgroundColor: Colors.lightBlue, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ), - ); - }, - child: const Column( - children: [ - TextAtom( - 'Hotspot name:', - style: TextStyle(color: Colors.white60), - ), - TextAtom( - 'CyBear Jinni', - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: Colors.white70, - ), - ), - ], - ), - ), + TextAtom( + 'CyBear Jinni', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Colors.white70, ), ), - const SizedBox( - height: 2, - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: SizedBox( - width: double.infinity, - height: 70, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.black12, - ), - ), - onPressed: () { - FlutterClipboard.copy('CyBear Jinni').then( - (value) => Fluttertoast.showToast( - msg: 'Copy', - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.SNACKBAR, - backgroundColor: Colors.lightBlue, - textColor: Theme.of(context) - .textTheme - .bodyLarge! - .color, - fontSize: 16.0, - ), - ); - }, - child: const Column( - children: [ - TextAtom( - 'Hotspot password:', - style: TextStyle(color: Colors.white60), - ), - TextAtom( - 'CyBear Jinni', - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - color: Colors.white70, - ), - ), - ], - ), - ), - ), + ], + ), + ), + ), + ), + const SizedBox( + height: 2, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: SizedBox( + width: double.infinity, + height: 70, + child: TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.black12, + ), + ), + onPressed: () { + FlutterClipboard.copy('CyBear Jinni').then( + (value) => Fluttertoast.showToast( + msg: 'Copy', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.SNACKBAR, + backgroundColor: Colors.lightBlue, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, ), - const SizedBox( - height: 10, + ); + }, + child: const Column( + children: [ + TextAtom( + 'Hotspot password:', + style: TextStyle(color: Colors.white60), ), - const SizedBox( - height: 20, + TextAtom( + 'CyBear Jinni', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + color: Colors.white70, + ), ), ], - ); - }, - cantDetermineAccessPointOpenOrNot: - (CantDetermineAccessPointOpenOrNot value) { - return const TextAtom('CantDetermineAccessPointOpenOrNot'); - }, - accessPointIsNotOpen: (AccessPointIsNotOpen value) { - return const TextAtom('AccessPointIsNotOpen'); - }, - accessPointIsOpen: (AccessPointIsOpen value) { - context.router.replace(const ScanForNewCBJCompsRoute()); - return const TextAtom('AccessPointIsOpen'); - }, - ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 50), - child: const TextAtom( - "Currently we can't verify that you have opened Access pont.\n" - 'Press next only after you have preformed the actions above!.', - style: TextStyle(fontSize: 17), - ), - ), - const SizedBox( - height: 30, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.greenAccent, ), ), - onPressed: () { - context - .read() - .add(ManageAccessPointEvent.doesAccessPointOpen()); - }, - child: const TextAtom('Next'), ), - ], - ), + ), + const SizedBox( + height: 10, + ), + const SizedBox( + height: 20, + ), + ], ); - }, + + case OpenAccessPointState.cantDetermineAccessPointOpenOrNot: + return const TextAtom('CantDetermineAccessPointOpenOrNot'); + + case OpenAccessPointState.accessPointIsNotOpen: + return const TextAtom('AccessPointIsNotOpen'); + + case OpenAccessPointState.accessPointIsOpen: + return const TextAtom('AccessPointIsOpen'); + } + } + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + children: [ + getStateWidget(), + Container( + margin: const EdgeInsets.symmetric(horizontal: 50), + child: const TextAtom( + "Currently we can't verify that you have opened Access pont.\n" + 'Press next only after you have preformed the actions above!.', + style: TextStyle(fontSize: 17), + ), + ), + const SizedBox( + height: 30, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.greenAccent, + ), + ), + onPressed: _doesAccessPointOpen, + child: const TextAtom('Next'), + ), + ], + ), ); } } + +enum OpenAccessPointState { + initial, + loading, + loaded, + error, + iOSDevice, + cantDetermineAccessPointOpenOrNot, + accessPointIsNotOpen, + accessPointIsOpen, + ; +} diff --git a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart index 72c9d22bc..5cdf47c5d 100644 --- a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart +++ b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart @@ -50,6 +50,7 @@ class _CbjHubInNetworkWidgetState extends State { return null; } if (devices.isNotEmpty) { + PhoneHub().startListen(); context.router.replace(const HomeRoute()); return; } diff --git a/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart b/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart index bbf1c8d36..1133128af 100644 --- a/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart +++ b/lib/presentation/pages/connect_to_hub_more/connect_to_hub_more_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/more_connections_options/more_connections_options_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hexcolor/hexcolor.dart'; @RoutePage() @@ -48,16 +45,7 @@ class ConnectToHubMorePage extends StatelessWidget { ), Expanded( child: Center( - child: BlocProvider( - create: (BuildContext context) => - getIt() - ..add( - MoreConnectionsOptionsEvent.initialEvent( - context, - ), - ), - child: ConnectToHubMoreWidget(), - ), + child: ConnectToHubMoreWidget(), ), ), const SizedBox( diff --git a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart index ac62c4d60..c6a3dc1ff 100644 --- a/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart +++ b/lib/presentation/pages/connect_to_hub_more/widgets/connect_to_hub_more_widget.dart @@ -1,150 +1,165 @@ -import 'package:cybear_jinni/application/more_connections_options/more_connections_options_bloc.dart'; +import 'dart:async'; + +import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/hub/i_hub_connection_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; +import 'package:kt_dart/kt.dart'; + +class ConnectToHubMoreWidget extends StatefulWidget { + @override + State createState() => _ConnectToHubMoreWidgetState(); +} + +class _ConnectToHubMoreWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + + bool isLoading = false; + + Future _connectInDemoMode() async { + context.router.replace(const HomeRoute()); + IHubConnectionRepository.instance.connectWithHub(demoMod: true); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + + super.dispose(); + } -class ConnectToHubMoreWidget extends StatelessWidget { @override Widget build(BuildContext context) { + if (isLoading) { + return const CircularProgressIndicatorAtom(); + } + final Size screenSize = MediaQuery.of(context).size; - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) { - return Column( + return Column( + children: [ + Expanded( + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 30), + child: Column( children: [ Expanded( - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 30), + child: ColoredBox( + color: HexColor('#985dc7'), child: Column( children: [ - Expanded( - child: ColoredBox( - color: HexColor('#985dc7'), - child: Column( - children: [ - const SizedBox( - height: 15, - ), - Container( - margin: const EdgeInsets.symmetric( - horizontal: 15, - ), - child: const Row( - children: [ - FaIcon( - FontAwesomeIcons.globe, - color: Colors.white, - ), - SizedBox( - width: 40, - ), - Flexible( - child: TextAtom( - 'Connect to Remote Pipes', - style: TextStyle( - color: Colors.white, - ), - ), - ), - ], - ), - ), - const Expanded( - child: Center( - child: TextAtom( - 'Currently not supported', - style: TextStyle(color: Colors.white), - ), - // BlocProvider( - // create: (context) => getIt() - // ..add( - // const HubInNetworkEvent - // .searchHubInNetwork(), - // ), - // child: CbjHubInNetwork(), - // ), + const SizedBox( + height: 15, + ), + Container( + margin: const EdgeInsets.symmetric( + horizontal: 15, + ), + child: const Row( + children: [ + FaIcon( + FontAwesomeIcons.globe, + color: Colors.white, + ), + SizedBox( + width: 40, + ), + Flexible( + child: TextAtom( + 'Connect to Remote Pipes', + style: TextStyle( + color: Colors.white, ), ), - ], + ), + ], + ), + ), + const Expanded( + child: Center( + child: TextAtom( + 'Currently not supported', + style: TextStyle(color: Colors.white), ), + // BlocProvider( + // create: (context) => getIt() + // ..add( + // const HubInNetworkEvent + // .searchHubInNetwork(), + // ), + // child: CbjHubInNetwork(), + // ), ), ), ], ), ), ), - SizedBox( - height: screenSize.height / 20, - ), - GestureDetector( - onTap: () { - context.read().add( - const MoreConnectionsOptionsEvent.connectInDemoMode(), - ); - // context.router.replace(const HomeRoute()); - }, - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 30), - height: 60, - color: HexColor('#985dc7'), - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 15), - child: Row( - children: [ - const FaIcon( - FontAwesomeIcons.vial, - color: Colors.white, - ), - const SizedBox( - width: 40, + ], + ), + ), + ), + SizedBox( + height: screenSize.height / 20, + ), + GestureDetector( + onTap: () { + _connectInDemoMode(); + }, + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 30), + height: 60, + color: HexColor('#985dc7'), + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 15), + child: Row( + children: [ + const FaIcon( + FontAwesomeIcons.vial, + color: Colors.white, + ), + const SizedBox( + width: 40, + ), + Flexible( + child: RichText( + text: TextSpan( + style: TextStyle( + color: Colors.white.withOpacity(0.9), + ), + children: const [ + TextSpan( + text: 'Open Demo\n', + style: TextStyle( + fontSize: 16, + color: Colors.white, + ), ), - Flexible( - child: RichText( - text: TextSpan( - style: TextStyle( - color: Colors.white.withOpacity(0.9), - ), - children: const [ - TextSpan( - text: 'Open Demo\n', - style: TextStyle( - fontSize: 16, - color: Colors.white, - ), - ), - TextSpan( - text: - 'Demo mod will not let you add or control ' - 'real smart home device!', - style: TextStyle( - color: Colors.white, - ), - ), - ], - ), + TextSpan( + text: 'Demo mod will not let you add or control ' + 'real smart home device!', + style: TextStyle( + color: Colors.white, ), ), ], ), ), ), - ), - ], - ); - }, - loadInProgress: (_) => const SizedBox( - height: 70, - width: 70, - child: CircularProgressIndicatorAtom(), + ], + ), + ), ), - loadSuccess: (_) => const TextAtom('Found hub'), - loadFailure: (failure) => const TextAtom('Failure'), - ); - }, + ), + ], ); } } diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart deleted file mode 100644 index a89b88c0c..000000000 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart +++ /dev/null @@ -1,89 +0,0 @@ -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// The page to add new routines -class AddBindingsPage extends StatelessWidget { - void backButtonFunction(BuildContext context) { - Navigator.pop(context); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - width: MediaQuery.of(context).size.width, - decoration: BoxDecoration( - gradient: LinearGradient( - // Where the linear gradient begins and ends - begin: Alignment.topRight, - end: Alignment.bottomCenter, - // Add one stop for each color. Stops should increase from 0 to 1 - stops: const [0, 0, 0, 1], - colors: [ - Theme.of(context).primaryColor, - Theme.of(context).colorScheme.secondary, - Theme.of(context).colorScheme.secondary, - Theme.of(context).primaryColor, - ], - ), - ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Add Binding', - rightIcon: null, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - ), - const SizedBox( - height: 100, - ), - const TextAtom( - 'Press here to set your home location', - style: TextStyle(fontSize: 20), - ), - const SizedBox( - height: 50, - ), - SizedBox( - height: 50, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.grey), - ), - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Set Home Location', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ), - const SizedBox( - height: 50, - ), - Container( - margin: const EdgeInsets.symmetric(horizontal: 20), - child: const TextAtom( - 'By pressing here you allow the app to access your location' - ' even when the app is not open.', - style: TextStyle(fontSize: 14), - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart b/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart deleted file mode 100644 index c290cf2d1..000000000 --- a/lib/presentation/pages/home_page/tabs/bindings_tab/bindings_page.dart +++ /dev/null @@ -1,138 +0,0 @@ -import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/home_page/tabs/bindings_tab/add_bindings/add_bindings_page.dart'; -import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; -import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// Page to see and interact with all the set routines -class BindingsPage extends StatelessWidget { - /// Execute when user press the icon in top right side - void userCogFunction(BuildContext context) { - showAdaptiveActionSheet( - context: context, - actions: [ - BottomSheetAction( - title: const TextAtom( - '⚙️ Bindings Settings', - style: TextStyle(color: Colors.blueGrey, fontSize: 23), - ), - onPressed: (_) {}, - ), - ], - ); - } - - void leftIconFunction(BuildContext context) { - Scaffold.of(context).openDrawer(); - } - - void rightSecondFunction(BuildContext context) {} - - @override - Widget build(BuildContext context) { - return Stack( - children: [ - Column( - children: [ - TopNavigationBar( - pageName: 'Bindings', - rightIcon: Icons.more_vert, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.userGear, - leftIconFunction: leftIconFunction, - rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - rightSecondFunction: rightSecondFunction, - ), - const SizedBox( - height: 10, - ), - Expanded( - child: GestureDetector( - onTap: () { - Fluttertoast.showToast( - msg: 'Add new binding by pressing the plus button', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - }, - child: ListView( - reverse: true, - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - Align( - alignment: Alignment.topCenter, - child: TextAtom( - 'Bindings list is empty', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).primaryColor, - ), - ), - ), - ], - ), - ), - ), - ], - ), - Column( - children: [ - const Expanded( - child: TextAtom(''), - ), - SizedBox( - height: 100, - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Transform.scale( - scale: 1.2, - child: GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - AddBindingsPage(), - ), - ); - }, - child: Ink( - decoration: const ShapeDecoration( - color: Colors.black12, - shape: CircleBorder(), - ), - child: CircleAvatar( - backgroundColor: Colors.blue.withOpacity(0.9), - child: const FaIcon( - FontAwesomeIcons.plus, - color: Colors.white, - ), - ), - ), - ), - ), - const SizedBox( - width: 15, - ), - ], - ), - ), - ], - ), - ], - ); - } -} diff --git a/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart b/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart deleted file mode 100644 index 88eebff42..000000000 --- a/lib/presentation/pages/home_page/tabs/history_tab/history_tab.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class HistoryTab extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Column( - children: [ - const Padding( - padding: EdgeInsets.only(top: 20), - ), - Container( - alignment: Alignment.centerRight, - child: IconButton( - icon: FaIcon( - FontAwesomeIcons.gear, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onPressed: () => Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => SettingsPageOfHistory(), - ), - ), - ), - ), - TextAtom( - 'Actions_History', - style: TextStyle( - fontSize: 23.0, - color: Theme.of(context).textTheme.bodyLarge!.color, - decoration: TextDecoration.underline, - ), - ), - Container( - height: 20, - ), - const TextAtom('Empty_history'), - ], - ); - } -} diff --git a/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart b/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart deleted file mode 100644 index ad18e4b4d..000000000 --- a/lib/presentation/pages/home_page/tabs/history_tab/settings_page_of_history.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -class SettingsPageOfHistory extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - width: MediaQuery.of(context).size.width, - padding: const EdgeInsets.all(5.0), - decoration: BoxDecoration( - gradient: LinearGradient( - // Where the linear gradient begins and ends - begin: Alignment.topRight, - end: Alignment.bottomCenter, - // Add one stop for each color. Stops should increase from 0 to 1 - stops: const [0, 0, 0, 1], - colors: [ - Theme.of(context).primaryColor, - Theme.of(context).colorScheme.secondary, - Theme.of(context).colorScheme.secondary, - Theme.of(context).primaryColor, - ], - ), - ), - child: Column( - children: [ - const Padding( - padding: EdgeInsets.only(top: 20), - ), - Container( - alignment: Alignment.centerLeft, - child: IconButton( - icon: FaIcon( - FontAwesomeIcons.arrowLeft, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onPressed: () => Navigator.pop(context), - ), - ), - TextAtom( - 'History_Settings_Page', - style: TextStyle( - fontSize: 23.0, - color: Theme.of(context).textTheme.bodyLarge!.color, - decoration: TextDecoration.underline, - ), - ), - ], - ), - ), - ); - } -} 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 f5529186a..ce07a16c5 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 @@ -1,11 +1,8 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; -import 'package:cybear_jinni/application/folders_of_scenes/folders_of_scenes_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -58,11 +55,7 @@ class ScenesInFoldersTab extends StatelessWidget { // rightSecondFunction: rightSecondFunction, ), Expanded( - child: BlocProvider( - create: (context) => getIt() - ..add(const FoldersOfScenesEvent.initialized()), - child: ScenesInFoldersL(), - ), + child: ScenesInFoldersL(), ), ], ); diff --git a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart index 0bf041820..a63379395 100644 --- a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart +++ b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/widgets/scenes_in_folders_l.dart @@ -1,52 +1,53 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/folders_of_scenes/folders_of_scenes_bloc.dart'; +import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; +import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; +import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:kt_dart/collection.dart'; -class ScenesInFoldersL extends StatelessWidget { +class ScenesInFoldersL extends StatefulWidget { @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - (value) => const TextAtom('sd'), - loading: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loaded: (state) { - return ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final RoomEntity sceneFolder = state.foldersOfScenes[index]; - return scenesFoldersWidget( - context, - sceneFolder, - ); - }, - itemCount: state.foldersOfScenes.length, - ); - }, - loadedEmpty: (LoadedEmpty value) { - return const Center( - child: TextAtom( - 'You can add automations in the plus button', - style: TextStyle( - fontSize: 18, - color: Colors.black, - ), - ), - ); - }, - error: (_) { - return const TextAtom('Error'); - }, - ); - }, - ); + State createState() => _ScenesInFoldersLState(); +} + +class _ScenesInFoldersLState extends State { + List allScenes = []; + List? allRoomsWithScenes; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + final List temp = []; + final List eitherAllScenes = + await ISceneCbjRepository.instance.getAllScenesAsList(); + allScenes.addAll(eitherAllScenes); + + if (allScenes.isEmpty) { + return; + } + + final dartz.Either> eitherAllRooms = + await IRoomRepository.instance.getAllRooms(); + eitherAllRooms.fold((l) => null, (KtList r) { + for (final RoomEntity rE in r.asList()) { + if (rE.roomScenesId.getOrCrash().isNotEmpty) { + temp.add(rE); + } + } + }); + + setState(() { + allRoomsWithScenes = temp; + }); } Widget scenesFoldersWidget( @@ -111,4 +112,36 @@ class ScenesInFoldersL extends StatelessWidget { ), ); } + + @override + Widget build(BuildContext context) { + if (allRoomsWithScenes == null) { + return const CircularProgressIndicatorAtom(); + } + + if (allRoomsWithScenes!.isEmpty) { + return const Center( + child: TextAtom( + 'You can add automations in the plus button', + style: TextStyle( + fontSize: 18, + color: Colors.black, + ), + ), + ); + } + + return ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final RoomEntity sceneFolder = allRoomsWithScenes![index]; + return scenesFoldersWidget( + context, + sceneFolder, + ); + }, + itemCount: allRoomsWithScenes!.length, + ); + } } diff --git a/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart b/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart deleted file mode 100644 index 5afa90a14..000000000 --- a/lib/presentation/pages/join_home_by_id/join_home_by_id_page.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/join_home_by_id/join_home_by_id_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -@RoutePage() -class JoinHomeByIdPage extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const TextAtom('Add home by ID'), - ), - backgroundColor: Colors.blueAccent.withOpacity(0.7), - body: BlocProvider( - create: (context) => getIt(), - child: JoinHomeByIdWidget(), - ), - ); - } -} diff --git a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart b/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart deleted file mode 100644 index 358c2b7bc..000000000 --- a/lib/presentation/pages/join_home_by_id/widgets/join_home_by_id_widget.dart +++ /dev/null @@ -1,129 +0,0 @@ -import 'package:auto_route/auto_route.dart'; -import 'package:clipboard/clipboard.dart'; -import 'package:cybear_jinni/application/join_home_by_id/join_home_by_id_bloc.dart'; -import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class JoinHomeByIdWidget extends StatelessWidget { - @override - Widget build(BuildContext context) { - String homeId = ''; - - return BlocConsumer( - listener: (context, state) { - state.map( - (value) => null, - loading: (_) { - return const CircularProgressIndicatorAtom(); - }, - loaded: (l) { - return const TextAtom('Loaded'); - }, - error: (e) { - return const TextAtom('Failure'); - }, - ); - }, - builder: (context, state) { - return Column( - children: [ - const SizedBox( - height: 30, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.green), - ), - onPressed: () async { - final String fromClipboard = await FlutterClipboard.paste(); - - context - .read() - .add(JoinHomeByIdEvent.addHomeById(fromClipboard)); - }, - child: TextAtom( - 'Paste and search', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - const SizedBox( - height: 70, - ), - Row( - children: [ - const SizedBox( - width: 10, - ), - const TextAtom('Home ID'), - const SizedBox( - width: 30, - ), - SizedBox( - width: 250, - child: TextFormField( - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - decoration: InputDecoration( - filled: true, - fillColor: Colors.greenAccent.withOpacity(0.3), - prefixIcon: Icon( - Icons.login, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - labelText: 'Home ID', - labelStyle: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - autocorrect: false, - onChanged: (value) { - homeId = value; - }, - ), - ), - ], - ), - const SizedBox( - height: 30, - ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.pinkAccent), - ), - onPressed: () { - context - .read() - .add(JoinHomeByIdEvent.addHomeById(homeId)); - }, - child: TextAtom( - 'Join Home from text form', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - state.map( - (value) => const SizedBox(), - loading: (_) { - return const CircularProgressIndicatorAtom(); - }, - loaded: (l) { - context.router.replace(const HomeRoute()); - - return const TextAtom('Loaded'); - }, - error: (e) { - return const TextAtom('Failure'); - }, - ), - ], - ); - }, - ); - } -} diff --git a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart index 47e5f25ea..a3c34256a 100644 --- a/lib/presentation/pages/remote_pipes/remote_pipes_page.dart +++ b/lib/presentation/pages/remote_pipes/remote_pipes_page.dart @@ -1,7 +1,5 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/remote_pipes/remote_pipes_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; @@ -36,34 +34,27 @@ class RemotePipesPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return MultiBlocListener( + listeners: const [], + child: Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, ), - ], - child: MultiBlocListener( - listeners: [], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Column( - children: [ - TopNavigationBar( - pageName: 'Remote Pipes', - rightIcon: null, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, - ), - Expanded( - child: RemotePipesWidget(), - ), - ], - ), + body: Column( + children: [ + TopNavigationBar( + pageName: 'Remote Pipes', + rightIcon: null, + rightIconFunction: userCogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: leftIconFunction, + ), + Expanded( + child: RemotePipesWidget(), + ), + ], ), ), ); diff --git a/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart b/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart index 8d237fdd8..264aaf863 100644 --- a/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart +++ b/lib/presentation/pages/remote_pipes/widgets/manage_remote_pipes_widget.dart @@ -1,76 +1,88 @@ -import 'package:cybear_jinni/application/remote_pipes/remote_pipes_bloc.dart'; +import 'package:cbj_integrations_controller/domain/remote_pipes/i_remote_pipes_repository.dart'; +import 'package:cbj_integrations_controller/domain/remote_pipes/remote_pipes_entity.dart'; +import 'package:cbj_integrations_controller/domain/remote_pipes/remote_pipes_value_objects.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show light toggles in a container with the background color from smart room /// object -class RemotePipesWidget extends StatelessWidget { +class RemotePipesWidget extends StatefulWidget { + @override + State createState() => _RemotePipesWidgetState(); +} + +class _RemotePipesWidgetState extends State { + String? remotePipesDomainName; + + @override + void initState() { + super.initState(); + } + + Future _remotePipesDomainChanged(String value) async { + setState(() { + remotePipesDomainName = value; + }); + } + + Future _addRemotePipeUrl() async { + if (remotePipesDomainName == null || remotePipesDomainName!.isEmpty) { + return; + } + + final RemotePipesEntity remotePipesEntity = + RemotePipesEntity.empty().copyWith( + domainName: RemotePipesDomain(remotePipesDomainName!), + ); + + Navigator.pop(context); + await IRemotePipesRepository.instance + .setRemotePipesDomainName(remotePipesEntity); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(horizontal: 30), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const TextAtom( - 'Please insert the Remote Pipes domain', - style: TextStyle(color: Colors.black, fontSize: 25), - ), - const SizedBox( - height: 60, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.globe), - labelText: 'Remote Pipes domain', - ), - autocorrect: false, - onChanged: (value) => context - .read() - .add(RemotePipesEvent.remotePipesDomainChanged(value)), - // validator: (_) => context - // .read() - // .state - // .tuyaUserName - // .value - // .fold( - // (CoreLoginFailure f) => 'Validation error', - // // f.maybeMap( - // // invalidEmail: (result) => result.failedValue, - // // containsSpace: (result) => result.failedValue, - // // orElse: () => null, - // // ), - // (r) => null, - // ), - ), - const SizedBox( - height: 30, - ), - TextButton( - onPressed: () { - Fluttertoast.showToast( - msg: 'Sending domain name to the Hub', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - context.read().add( - RemotePipesEvent.addRemotePipeUrl(context), - ); - }, - child: const TextAtom('Connect'), - ), - ], + return Container( + margin: const EdgeInsets.symmetric(horizontal: 30), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const TextAtom( + 'Please insert the Remote Pipes domain', + style: TextStyle(color: Colors.black, fontSize: 25), + ), + const SizedBox( + height: 60, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon(FontAwesomeIcons.globe), + labelText: 'Remote Pipes domain', + ), + autocorrect: false, + onChanged: _remotePipesDomainChanged, + ), + const SizedBox( + height: 30, + ), + TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Sending domain name to the Hub', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.blueGrey, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _addRemotePipeUrl(); + }, + child: const TextAtom('Connect'), ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/routes/app_router.dart b/lib/presentation/pages/routes/app_router.dart index 75f67239b..880d321a8 100644 --- a/lib/presentation/pages/routes/app_router.dart +++ b/lib/presentation/pages/routes/app_router.dart @@ -10,14 +10,12 @@ class AppRouter extends $AppRouter { AutoRoute(page: ConnectToHubRoute.page), AutoRoute(page: ConnectToHubMoreRoute.page), AutoRoute(page: ChooseDeviceVendorToAddRoute.page), - AutoRoute(page: JoinHomeByIdRoute.page), AutoRoute(page: HomeRoute.page), AutoRoute(page: ChangeRoomForDevicesRoute.page), AutoRoute(page: AddNewRoomRoute.page), AutoRoute(page: PlusButtonRoute.page), AutoRoute(page: RemotePipesRoute.page), AutoRoute(page: SoftwareInfoRoute.page), - AutoRoute(page: ManageUsersRoute.page), AutoRoute(page: ScenesRoute.page), AutoRoute(page: AddSceneRoute.page), AutoRoute(page: AddRoutineRoute.page), diff --git a/lib/presentation/pages/scenes/scenes_page.dart b/lib/presentation/pages/scenes/scenes_page.dart index 00392e2aa..5830965c6 100644 --- a/lib/presentation/pages/scenes/scenes_page.dart +++ b/lib/presentation/pages/scenes/scenes_page.dart @@ -3,14 +3,11 @@ import 'dart:ui'; import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/folder_of_scenes/folder_of_scenes_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/scenes/widgets/folder_of_scenes.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -79,17 +76,7 @@ class ScenesPage extends StatelessWidget { // ), Expanded( - child: BlocProvider( - create: (context) => getIt() - ..add( - FolderOfScenesEvent.initialized( - folderOfScenes: folderOfScenes, - ), - ), - child: FolderOfScenesWidget( - folderOfScenes: folderOfScenes, - ), - ), + child: FolderOfScenesWidget(folderOfScenes: folderOfScenes), ), ], ), diff --git a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart index f70ac21b4..28492a0d3 100644 --- a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart +++ b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart @@ -1,23 +1,58 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_failures.dart'; -import 'package:cybear_jinni/application/folder_of_scenes/folder_of_scenes_bloc.dart'; import 'package:cybear_jinni/application/scene/scene_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/scenes/widgets/scene_widget.dart'; -import 'package:dartz/dartz.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -class FolderOfScenesWidget extends StatelessWidget { +class FolderOfScenesWidget extends StatefulWidget { const FolderOfScenesWidget({required this.folderOfScenes}); final RoomEntity folderOfScenes; + @override + State createState() => _FolderOfScenesWidgetState(); +} + +class _FolderOfScenesWidgetState extends State { + late RoomEntity folderOfScenes; + + List allScenesInTheRoom = []; + List? scenesList; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + folderOfScenes = widget.folderOfScenes; + + final Map eitherAllScenes = + await ISceneCbjRepository.instance.getAllScenesAsMap(); + for (final String sceneId in folderOfScenes.roomScenesId.getOrCrash()) { + if (eitherAllScenes.containsKey(sceneId)) { + allScenesInTheRoom.add(eitherAllScenes[sceneId]!); + } + } + + if (allScenesInTheRoom.isEmpty) { + return; + } + + setState(() { + scenesList = allScenesInTheRoom; + }); + } + SceneCbjEntity getTheScene( - Either scenesList, + dartz.Either scenesList, ) { return scenesList.fold((l) => throw 'Invalid value', (r) => r); } @@ -30,62 +65,38 @@ class FolderOfScenesWidget extends StatelessWidget { if (screenSize.width > 700) { gridCrossAxisCount = 4; } - - return BlocConsumer( - listener: (context, FolderOfScenesState state) { - state.map( - (value) => (v) { - return const TextAtom('value'); - }, - loading: (loadingNow) { - return const TextAtom('loading'); - }, - error: (errorNow) { - FlushbarHelper.createError(message: 'Error'); - }, - loaded: (_) => const TextAtom('Loaded'), - loadedEmptyScens: (LoadedEmptyScens value) {}, - ); - }, - builder: (context, state) { - return state.map( - (value) => const TextAtom('Start'), - loading: (_) => const TextAtom('loading'), - loaded: (scenesList) { - return GridView.builder( - reverse: true, - itemBuilder: (context, index) { - final SceneCbjEntity sceneCbj = scenesList.scenesList[index]; - return BlocProvider( - create: (context) => getIt() - ..add( - SceneEvent.initialized( - sceneCbj: sceneCbj, - ), - ), - child: SceneWidget(sceneCbj), - ); - }, - itemCount: scenesList.scenesList.length, - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: gridCrossAxisCount, - ), - ); - }, - loadedEmptyScens: (LoadedEmptyScens value) { - return const Center( - child: TextAtom( - 'You can add automations in the plus button', - style: TextStyle( - fontSize: 18, - color: Colors.black, - ), + if (scenesList == null) { + return const CircularProgressIndicatorAtom(); + } + if (scenesList!.isEmpty || allScenesInTheRoom.isEmpty) { + return const Center( + child: TextAtom( + 'You can add automations in the plus button', + style: TextStyle( + fontSize: 18, + color: Colors.black, + ), + ), + ); + } + return GridView.builder( + reverse: true, + itemBuilder: (context, index) { + final SceneCbjEntity sceneCbj = scenesList![index]; + return BlocProvider( + create: (context) => getIt() + ..add( + SceneEvent.initialized( + sceneCbj: sceneCbj, ), - ); - }, - error: (_) => const TextAtom('error'), + ), + child: SceneWidget(sceneCbj), ); }, + itemCount: scenesList!.length, + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: gridCrossAxisCount, + ), ); } } diff --git a/lib/presentation/pages/splash/splash_page.dart b/lib/presentation/pages/splash/splash_page.dart index ba629f497..c3302f634 100644 --- a/lib/presentation/pages/splash/splash_page.dart +++ b/lib/presentation/pages/splash/splash_page.dart @@ -17,6 +17,7 @@ class _SplashPageState extends State { @override void initState() { super.initState(); + _navigate(); } From d977d791b8e780d0f1f49b26cf77ba5d8cff2baa Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 12:45:48 +0200 Subject: [PATCH 12/15] Removed unused flows --- .../add_user_to_home_entity.dart | 30 ---- .../add_user_to_home_errors.dart | 14 -- .../add_user_to_home_failures.dart | 26 --- .../add_user_to_home_validators.dart | 28 --- .../add_user_to_home_value_objects.dart | 94 ---------- .../i_add_user_to_home_repository.dart | 20 --- lib/domain/auth/auth_failure.dart | 19 --- lib/domain/auth/i_auth_facade.dart | 42 ----- lib/domain/auth/user.dart | 18 -- lib/domain/auth/value_objects.dart | 32 ---- .../home_user/i_home_user_repository.dart | 21 --- lib/domain/user/i_user_repository.dart | 70 ++++---- .../add_user_to_home_dtos.dart | 63 ------- .../add_user_to_home_reposityory.dart | 91 ---------- .../cbj_comp/cbj_comp_repository.dart | 144 +--------------- .../devices/device/device_repository.dart | 7 +- .../home_user/home_user_dtos.dart | 55 ------ .../home_user/home_user_repository.dart | 98 ----------- .../hub_auth_facade/hub_auth_facade.dart | 102 ----------- .../security_bear_client_delete.dart | 88 ---------- .../security_bear_connection_repository.dart | 5 +- .../all_homes_of_user_dtos.dart | 52 ------ lib/infrastructure/user/user_dtos.dart | 59 ------- lib/infrastructure/user/user_repository.dart | 161 ------------------ 24 files changed, 39 insertions(+), 1300 deletions(-) delete mode 100644 lib/domain/add_user_to_home/add_user_to_home_entity.dart delete mode 100644 lib/domain/add_user_to_home/add_user_to_home_errors.dart delete mode 100644 lib/domain/add_user_to_home/add_user_to_home_failures.dart delete mode 100644 lib/domain/add_user_to_home/add_user_to_home_validators.dart delete mode 100644 lib/domain/add_user_to_home/add_user_to_home_value_objects.dart delete mode 100644 lib/domain/add_user_to_home/i_add_user_to_home_repository.dart delete mode 100644 lib/domain/auth/auth_failure.dart delete mode 100644 lib/domain/auth/i_auth_facade.dart delete mode 100644 lib/domain/auth/user.dart delete mode 100644 lib/domain/auth/value_objects.dart delete mode 100644 lib/domain/home_user/i_home_user_repository.dart delete mode 100644 lib/infrastructure/add_user_to_home/add_user_to_home_dtos.dart delete mode 100644 lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart delete mode 100644 lib/infrastructure/home_user/home_user_dtos.dart delete mode 100644 lib/infrastructure/home_user/home_user_repository.dart delete mode 100644 lib/infrastructure/hub_auth_facade/hub_auth_facade.dart delete mode 100644 lib/infrastructure/security_bear_client/security_bear_client_delete.dart delete mode 100644 lib/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart delete mode 100644 lib/infrastructure/user/user_dtos.dart delete mode 100644 lib/infrastructure/user/user_repository.dart diff --git a/lib/domain/add_user_to_home/add_user_to_home_entity.dart b/lib/domain/add_user_to_home/add_user_to_home_entity.dart deleted file mode 100644 index f272d0325..000000000 --- a/lib/domain/add_user_to_home/add_user_to_home_entity.dart +++ /dev/null @@ -1,30 +0,0 @@ -// import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -// import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_value_objects.dart'; -// import 'package:dartz/dartz.dart'; -// import 'package:freezed_annotation/freezed_annotation.dart'; -// -// part 'add_user_to_home_entity.freezed.dart'; -// -// @freezed -// abstract class AddUserToHomeEntity implements _$AddUserToHomeEntity { -// const AddUserToHomeEntity._(); -// -// const factory AddUserToHomeEntity({ -// /// User to add unique id -// required AddUserToHomeUniqueId id, -// required AddUserToHomeEmail email, -// required AddUserToHomeName name, -// required AddUserToHomePermission permission, -// }) = _AddUserToHomeEntity; -// -// factory AddUserToHomeEntity.empty() => AddUserToHomeEntity( -// id: AddUserToHomeUniqueId(), -// name: AddUserToHomeName(''), -// email: AddUserToHomeEmail(''), -// permission: AddUserToHomePermission(''), -// ); -// -// Option> get failureOption { -// return email.value.fold((f) => some(f), (_) => none()); -// } -// } diff --git a/lib/domain/add_user_to_home/add_user_to_home_errors.dart b/lib/domain/add_user_to_home/add_user_to_home_errors.dart deleted file mode 100644 index 1ed1d25cd..000000000 --- a/lib/domain/add_user_to_home/add_user_to_home_errors.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; - -class AddUserToHomeUnexpectedValueError extends Error { - AddUserToHomeUnexpectedValueError(this.addUserValueFailure); - - final AddUserToHomeFailures addUserValueFailure; - - @override - String toString() { - const explanation = - 'Encountered a ValueFailure at an unrecoverable point. Terminating.'; - return Error.safeToString('$explanation Failure was: $addUserValueFailure'); - } -} diff --git a/lib/domain/add_user_to_home/add_user_to_home_failures.dart b/lib/domain/add_user_to_home/add_user_to_home_failures.dart deleted file mode 100644 index e6dd99e35..000000000 --- a/lib/domain/add_user_to_home/add_user_to_home_failures.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'add_user_to_home_failures.freezed.dart'; - -@freezed -class AddUserToHomeFailures { - const factory AddUserToHomeFailures.empty({ - required T failedValue, - }) = _Empty; - - const factory AddUserToHomeFailures.unexpected() = _Unexpected; - - const factory AddUserToHomeFailures.validateEmailNotEmpty() = - _ValidateEmailNotEmpty; - - const factory AddUserToHomeFailures.insufficientPermission() = - _InsufficientPermission; - - const factory AddUserToHomeFailures.cancelledByUser() = CancelledByUser; - - const factory AddUserToHomeFailures.serverError() = ServerError; - - const factory AddUserToHomeFailures.emailAlreadyExist() = EmailAlreadyExist; - - const factory AddUserToHomeFailures.cannotFindUser() = CannotFindUser; -} diff --git a/lib/domain/add_user_to_home/add_user_to_home_validators.dart b/lib/domain/add_user_to_home/add_user_to_home_validators.dart deleted file mode 100644 index 94eb5dfac..000000000 --- a/lib/domain/add_user_to_home/add_user_to_home_validators.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:dartz/dartz.dart'; - -Either, String> - validateAddUserToHomeEmailNotEmpty(String input) { - if (input.isNotEmpty) { - return right(input); - } else { - return left( - AddUserToHomeFailures.empty( - failedValue: input, - ), - ); - } -} - -Either, String> - validateAddUserToHomePermissionExist(String input) { - if (input.isNotEmpty) { - return right(input); - } else { - return left( - AddUserToHomeFailures.empty( - failedValue: input, - ), - ); - } -} diff --git a/lib/domain/add_user_to_home/add_user_to_home_value_objects.dart b/lib/domain/add_user_to_home/add_user_to_home_value_objects.dart deleted file mode 100644 index e10dacccd..000000000 --- a/lib/domain/add_user_to_home/add_user_to_home_value_objects.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_errors.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_validators.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/foundation.dart'; -import 'package:uuid/uuid.dart'; - -@immutable -abstract class AddUserToHomeValueObjectAbstract { - const AddUserToHomeValueObjectAbstract(); - - Either, T> get value; - - /// Throws [UnexpectedValueError] containing the [AddUserFailures] - T getOrCrash() { - // id = identity - same as writing (right) => right - return value.fold((f) => throw AddUserToHomeUnexpectedValueError(f), id); - } - - Either, Unit> get failureOrUnit { - return value.fold((l) => left(l), (r) => right(unit)); - } - - bool isValid() => value.isRight(); - - @override - String toString() => 'Value($value)'; - - @override - @nonVirtual - bool operator ==(Object o) { - if (identical(this, o)) return true; - return o is AddUserToHomeValueObjectAbstract && o.value == value; - } - - @override - int get hashCode => value.hashCode; -} - -class AddUserToHomeUniqueId extends AddUserToHomeValueObjectAbstract { - factory AddUserToHomeUniqueId() { - return AddUserToHomeUniqueId._(right(const Uuid().v1())); - } - - factory AddUserToHomeUniqueId.fromUniqueString(String uniqueId) { - return AddUserToHomeUniqueId._(right(uniqueId)); - } - - const AddUserToHomeUniqueId._(this.value); - - @override - final Either, String> value; -} - -class AddUserToHomeEmail extends AddUserToHomeValueObjectAbstract { - factory AddUserToHomeEmail(String input) { - return AddUserToHomeEmail._( - validateAddUserToHomeEmailNotEmpty(input), - ); - } - - const AddUserToHomeEmail._(this.value); - - @override - final Either, String> value; - - static const maxLength = 1000; -} - -class AddUserToHomeName extends AddUserToHomeValueObjectAbstract { - factory AddUserToHomeName(String input) { - return AddUserToHomeName._( - validateAddUserToHomeEmailNotEmpty(input), - ); - } - - const AddUserToHomeName._(this.value); - - @override - final Either, String> value; -} - -class AddUserToHomePermission extends AddUserToHomeValueObjectAbstract { - factory AddUserToHomePermission(String input) { - return AddUserToHomePermission._( - validateAddUserToHomePermissionExist(input), - ); - } - - const AddUserToHomePermission._(this.value); - - @override - final Either, String> value; -} diff --git a/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart b/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart deleted file mode 100644 index e0525a4f6..000000000 --- a/lib/domain/add_user_to_home/i_add_user_to_home_repository.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart'; -import 'package:dartz/dartz.dart'; - -abstract interface class IAddUserToHomeRepository { - static IAddUserToHomeRepository? _instance; - - static IAddUserToHomeRepository get instance { - return _instance ??= AddUserToHomeRepository(); - } - - Future> add( - HomeUserEntity homeUserEntity, - ); - - Future> create( - HomeUserEntity homeUserEntity, - ); -} diff --git a/lib/domain/auth/auth_failure.dart b/lib/domain/auth/auth_failure.dart deleted file mode 100644 index e349b8b27..000000000 --- a/lib/domain/auth/auth_failure.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'auth_failure.freezed.dart'; - -@freezed -class AuthFailure with _$AuthFailure { - /// When user canceled the auth - const factory AuthFailure.cancelledByUser() = CancelledByUser; - - /// Un specified server error - const factory AuthFailure.serverError() = ServerError; - - /// Email is already in use while trying to register - const factory AuthFailure.emailAlreadyInUse() = EmailAlreadyInUse; - - /// Wrong credentials while authenticating - const factory AuthFailure.invalidEmailAndPasswordCombination() = - InvalidEmailAndPasswordCombination; -} diff --git a/lib/domain/auth/i_auth_facade.dart b/lib/domain/auth/i_auth_facade.dart deleted file mode 100644 index 25a8823b4..000000000 --- a/lib/domain/auth/i_auth_facade.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:cybear_jinni/domain/auth/user.dart'; -import 'package:cybear_jinni/domain/auth/value_objects.dart'; -import 'package:cybear_jinni/infrastructure/hub_auth_facade/hub_auth_facade.dart'; -import 'package:dartz/dartz.dart'; - -// Class that starts with I is interface. -// Facade is a design pattern for connecting two or more classes which have -// weird interfaces and you can cannot really use those interfaces in your app -// facade takes those multiple classes and plug them into a nice unified -// interface. - -// FirebaseAuth, GoogleSignIn - -abstract interface class IAuthFacade { - static IAuthFacade? _instance; - - static IAuthFacade get instance { - return _instance ??= HubAuthFacade(); - } - - Future> getSignedInUser(); - - Future> getCurrentHome(); - - Future> registerWithEmailAndPassword({ - required EmailAddress emailAddress, - required Password password, - }); - - Future> registerWithEmailAndPasswordReturnUserId({ - required EmailAddress emailAddress, - required Password password, - }); - - Future> signInWithEmailAndPassword({ - required EmailAddress emailAddress, - required Password password, - }); - - Future signOut(); -} diff --git a/lib/domain/auth/user.dart b/lib/domain/auth/user.dart deleted file mode 100644 index d1094187d..000000000 --- a/lib/domain/auth/user.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'user.freezed.dart'; - -@freezed -class MUser with _$MUser { - const factory MUser({ - required UniqueId id, - }) = _MUser; -} - -@freezed -class MHome with _$MHome { - const factory MHome({ - required UniqueId id, - }) = _MHome; -} diff --git a/lib/domain/auth/value_objects.dart b/lib/domain/auth/value_objects.dart deleted file mode 100644 index a69cb8f66..000000000 --- a/lib/domain/auth/value_objects.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:cbj_integrations_controller/domain/core/failures.dart'; -import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; -import 'package:cybear_jinni/domain/core/value_validators.dart'; -import 'package:dartz/dartz.dart'; - -class EmailAddress extends ValueObject { - factory EmailAddress(String input) { - return EmailAddress._( - validateEmailAddress(input) - .flatMap((result) => validateEmailWithoutSpace(result)), - ); - } - - const EmailAddress._(this.value); - - @override - final Either, String> value; -} - -class Password extends ValueObject { - factory Password(String input) { - return Password._( - validatePasswordLength(input) - .flatMap((result) => validatePasswordWithoutSpace(result)), - ); - } - - const Password._(this.value); - - @override - final Either, String> value; -} diff --git a/lib/domain/home_user/i_home_user_repository.dart b/lib/domain/home_user/i_home_user_repository.dart deleted file mode 100644 index cabd775c5..000000000 --- a/lib/domain/home_user/i_home_user_repository.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/infrastructure/home_user/home_user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:kt_dart/collection.dart'; - -abstract interface class IHomeUserRepository { - static IHomeUserRepository? _instance; - - static IHomeUserRepository get instance { - return _instance ??= HomeUserRepository(); - } - - Stream>> getAllUsers(); - - Future> add(HomeUserEntity deviceEntity); - - Future> update(HomeUserEntity deviceEntity); - - Future> delete(HomeUserEntity deviceEntity); -} diff --git a/lib/domain/user/i_user_repository.dart b/lib/domain/user/i_user_repository.dart index 9430fb2ba..bf5dcf64e 100644 --- a/lib/domain/user/i_user_repository.dart +++ b/lib/domain/user/i_user_repository.dart @@ -1,35 +1,35 @@ -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_failures.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/infrastructure/user/user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:kt_dart/kt.dart'; - -abstract interface class IUserRepository { - static IUserRepository? _instance; - - static IUserRepository get instance { - return _instance ??= UserRepository(); - } - - Future> create(UserEntity deviceEntity); - - Future> addHome( - UserEntity userEntity, - AllHomesOfUserEntity allHomesOfUserEntity, - ); - - Future> joinExistingHome( - AllHomesOfUserEntity allHomesOfUserEntity, - ); - - Stream>> - watchAll(); - - Future> update(UserEntity deviceEntity); - - Future> getCurrentUser(); - - Future> delete(UserEntity deviceEntity); -} +// import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; +// import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; +// import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_failures.dart'; +// import 'package:cybear_jinni/domain/user/user_entity.dart'; +// import 'package:cybear_jinni/infrastructure/user/user_repository.dart'; +// import 'package:dartz/dartz.dart'; +// import 'package:kt_dart/kt.dart'; +// +// abstract interface class IUserRepository { +// static IUserRepository? _instance; +// +// static IUserRepository get instance { +// return _instance ??= UserRepository(); +// } +// +// Future> create(UserEntity deviceEntity); +// +// Future> addHome( +// UserEntity userEntity, +// AllHomesOfUserEntity allHomesOfUserEntity, +// ); +// +// Future> joinExistingHome( +// AllHomesOfUserEntity allHomesOfUserEntity, +// ); +// +// Stream>> +// watchAll(); +// +// Future> update(UserEntity deviceEntity); +// +// Future> getCurrentUser(); +// +// Future> delete(UserEntity deviceEntity); +// } diff --git a/lib/infrastructure/add_user_to_home/add_user_to_home_dtos.dart b/lib/infrastructure/add_user_to_home/add_user_to_home_dtos.dart deleted file mode 100644 index d301177cb..000000000 --- a/lib/infrastructure/add_user_to_home/add_user_to_home_dtos.dart +++ /dev/null @@ -1,63 +0,0 @@ -// import 'package:cloud_firestore/cloud_firestore.dart'; -// import 'package:cybear_jinni/domain/add_user/add_user_to_home_value_objects.dart'; -// import 'package:cybear_jinni/domain/generic_devices/device_entity.dart'; -// import 'package:cybear_jinni/domain/generic_devices/value_objects.dart'; -// import 'package:freezed_annotation/freezed_annotation.dart'; -// -// part 'add_user_dtos.freezed.dart'; -// part 'add_user_dtos.g.dart'; -// -// @freezed -// abstract class AddUserDtos implements _$AddUserDtos { -// const AddUserDtos._(); -// -// const factory AddUserDtos({ -// @JsonKey(includeFromJson: true) String id, -// required AddUserEmail email, -// required AddUserPermission permission, -// required String name, -// required String lastName, -// }) = _AddUserDtos; -// -// factory AddUserDtos.fromDomain(GenericLightDE deviceEntity) { -// return AddUserDtos( -// id: deviceEntity.id.getOrCrash(), -// cbjEntityName: deviceEntity.cbjEntityName.getOrCrash(), -// -// ); -// } -// -// GenericLightDE toDomain() { -// return GenericLightDE( -// id: DeviceUniqueId.fromUniqueString(id), -// cbjEntityName: CbjEntityName(cbjEntityName), -// roomId: DeviceUniqueId.fromUniqueString(roomId), -// state: EntityState(state), -// stateMassage: DeviceStateMassage(stateMassage), -// senderDeviceOs: DeviceSenderDeviceOs(senderDeviceOs), -// senderDeviceModel: DeviceSenderDeviceModel(senderDeviceModel), -// senderId: DeviceSenderId.fromUniqueString(senderId), -// action: DeviceAction(action), -// type: DeviceType(type), -// ); -// } -// -// factory AddUserDtos.fromJson(Map json) => -// _$AddUserDtosFromJson(json); -// -// factory AddUserDtos.fromFirestore(DocumentSnapshot doc) { -// return AddUserDtos.fromJson(doc.data()).copyWith(id: doc.id); -// } -// } -// -// class ServerTimestampConverter implements JsonConverter { -// const ServerTimestampConverter(); -// -// @override -// FieldValue fromJson(Object json) { -// return FieldValue.serverTimestamp(); -// } -// -// @override -// Object toJson(FieldValue fieldValue) => fieldValue; -// } diff --git a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart b/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart deleted file mode 100644 index a4f343350..000000000 --- a/lib/infrastructure/add_user_to_home/add_user_to_home_reposityory.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_errors.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/add_user_to_home_failures.dart'; -import 'package:cybear_jinni/domain/add_user_to_home/i_add_user_to_home_repository.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/infrastructure/home_user/home_user_dtos.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; - -class AddUserToHomeRepository implements IAddUserToHomeRepository { - AddUserToHomeRepository(); - - @override - @required - Future> create( - HomeUserEntity homeUserEntity, - ) async { - try { - // final devicesDoc = await _firestore.currentHomeDocument(); - // - homeUserEntity.id!.getOrCrash()!; - // final String userName = addUserToHomeEntity.name.getOrCrash(); - // final String userEmail = addUserToHomeEntity.email.getOrCrash(); - - HomeUserDtos.fromDomain(homeUserEntity); - - // await devicesDoc.usersCollecttion.doc(userId).set(homeUserDtos.toJson()); - return right(unit); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const AddUserToHomeFailures.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(const AddUserToHomeFailures.unexpected()); - } - } - } - - Future>> getUserByEmail( - String email, - ) async { - try { - // final devicesDoc = await _firestore.usersCollection(); - // final QuerySnapshot querySnapshot = - // await devicesDoc.where('email', isEqualTo: email).snapshots().first; - // final List queryDocSnapList = querySnapshot.docs; - // final QueryDocumentSnapshot queryDocSnap = queryDocSnapList.first; - // return right(queryDocSnap); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const AddUserToHomeFailures.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(const AddUserToHomeFailures.unexpected()); - } - } - return left(const AddUserToHomeFailures.unexpected()); - } - - @override - Future> add( - HomeUserEntity homeUserEntity, - ) async { - try { - final Either> - userDocOrFailure = - await getUserByEmail(homeUserEntity.email!.getOrCrash()!); - userDocOrFailure.fold( - (f) => throw AddUserToHomeUnexpectedValueError(f), - (r) => r, - ); - - // required AddUserToHomeEmail email, - // required AddUserToHomeName name, - // required AddUserToHomePermission permission, - // - // final HomeUserEntity homeUserEntityToAdd = homeUserEntity.copyWith( - // id: HomeUserUniqueId.fromUniqueString(userDocument.id), - // name: HomeUserName(userDocument.get('name').toString()), - // email: HomeUserEmail(userDocument.get('email').toString()), - // ); - - // await create(homeUserEntityToAdd); - final String homeId = await ILocalDbRepository2.instance.getHomeId(); - return Right(homeId); - } catch (e) { - return const Left(AddUserToHomeFailures.unexpected()); - } - } -} diff --git a/lib/infrastructure/cbj_comp/cbj_comp_repository.dart b/lib/infrastructure/cbj_comp/cbj_comp_repository.dart index b25cd01e0..7a580c4d6 100644 --- a/lib/infrastructure/cbj_comp/cbj_comp_repository.dart +++ b/lib/infrastructure/cbj_comp/cbj_comp_repository.dart @@ -19,39 +19,6 @@ class CBJCompRepository implements ICBJCompRepository { CBJCompEntity cBJCompEntity, ) async { try { - // final CompHubInfo compInfo = await compEntityToCompInfo(cBJCompEntity); - // - // final UserEntity deviceUser = - // (await ICreateHomeRepository.instance.getDeviceUserFromHome()) - // .getOrElse(() => throw "Device user can't be found"); - // - // final String fireBaseProjectId = ConstantCredentials.fireBaseProjectId; - // final String fireBaseApiKey = ConstantCredentials.fireBaseApiKey; - // final String userEmail = deviceUser.email!.getOrCrash(); - // final String userPassword = deviceUser.pass!.getOrCrash(); - // final String homeId = (await IAuthFacade.instance.getCurrentHome()) - // .getOrElse(() => throw MissingCurrentHomeError()) - // .id - // .getOrCrash()!; - // - // final FirebaseAccountInformation firebaseAccountInformation = - // FirebaseAccountInformation() - // ..fireBaseProjectId = fireBaseProjectId - // ..fireBaseApiKey = fireBaseApiKey - // ..userEmail = userEmail - // ..userPassword = userPassword - // ..homeId = homeId; - // - // final FirstSetupMessage firstSetupMessage = FirstSetupMessage( - // compInfo: compInfo, - // firebaseAccountInformation: firebaseAccountInformation); - // - // final CommendStatus commendStatus = await SmartClient.compFirstSetup( - // cBJCompEntity.lastKnownIp!.getOrCrash(), firstSetupMessage); - // - // if (commendStatus.success) { - // return right(unit); - // } return left(const CBJCompFailure.unexpected()); } catch (e) { return left(const CBJCompFailure.unexpected()); @@ -75,14 +42,6 @@ class CBJCompRepository implements ICBJCompRepository { CBJCompEntity compEntity, ) async { try { - // final CompHubInfo compInfo = await compEntityToCompInfo(compEntity); - // - // final CommendStatus commendStatus = await SmartClient.setCompInfo( - // compEntity.lastKnownIp!.getOrCrash(), compInfo); - // - // if (commendStatus.success) { - // return right(unit); - // } return left(const CBJCompFailure.unexpected()); } catch (e) { return left(const CBJCompFailure.unexpected()); @@ -113,110 +72,9 @@ class CBJCompRepository implements ICBJCompRepository { Future> getInformationFromDeviceByIp( String compIp, ) async { - try { - // final CompHubInfo compInfo = await SmartClient.getCompInfo(compIp); - // - // final CompSpecs compSpecs = compInfo.compSpecs; - // - // final KtList deviceEntityList = - // compDevicesToDevicesList(compInfo, compIp); - // - // final CBJCompEntity cbjCompEntity = CBJCompEntity( - // id: CBJCompUniqueId.fromUniqueString(compSpecs.compId), - // roomId: CBJCompRoomId(), - // compUuid: CBJCompUuid(compInfo.compSpecs.compUuid), - // lastKnownIp: CBJCompLastKnownIp(compIp), - // cBJCompDevices: CBJCompDevices(deviceEntityList), - // ); - // - // return right(cbjCompEntity); - } catch (e) { + try {} catch (e) { return left(const CBJCompFailure.unexpected()); } return left(const CBJCompFailure.unexpected()); } - - // Future compEntityToCompInfo(CBJCompEntity compEntity) async { - // String deviceModelString = 'No Model found'; - // final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); - // if (Platform.isAndroid) { - // final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; - // logger.i(androidInfo.model); - // deviceModelString = androidInfo.model!; - // } else if (Platform.isIOS) { - // final IosDeviceInfo iosInfo = await deviceInfo.iosInfo; - // logger.i(iosInfo.utsname.machine); - // deviceModelString = iosInfo.model!; - // } - // - // final CompHubSpecs compSpecs = CompHubSpecs( - // compUuid: compEntity.compUuid!.getOrCrash(), - // compId: compEntity.id.getOrCrash(), - // ); - // - // final List smartDevicesList = []; - // - // final EntityActions deviceAction = EntityActions.actionNotSupported; - // final EntityStateGRPC entityStateGRPC = EntityStateGRPC.waitingInComp; - // - // compEntity.cBJCompDevices!.getOrCrash().forEach((GenericLightDE element) { - // final DeviceTypesActions deviceTypesActions = DeviceTypesActions( - // deviceAction: deviceAction, - // entityStateGRPC: entityStateGRPC, - // ); - // - // final SmartDeviceInfo smartDeviceInfo = SmartDeviceInfo( - // compSpecs: compSpecs, - // deviceTypesActions: deviceTypesActions, - // cbjEntityName: element.cbjEntityName.getOrCrash(), - // senderId: element.senderId.getOrCrash(), - // senderDeviceModel: deviceModelString, - // senderDeviceOs: Platform.operatingSystem, - // state: element.entityStateGRPC.getOrCrash(), - // stateMassage: 'Setting up device', - // roomId: element.roomId.getOrCrash(), - // id: element.uniqueId.getOrCrash(), - // serverTimeStamp: DateTime.now().toString(), - // ); -// smartDevicesList.add(smartDeviceInfo); -// }); -// -// final CompHubInfo compInfo = CompHubInfo( -// compSpecs: compSpecs, -// ); -// return compInfo; -// } - -// KtList compDevicesToDevicesList( -// CompHubInfo compInfo, -// String compIp, -// ) { -// final List deviceEntityList = []; -// -// for (final SmartDeviceInfo smartDeviceInfo in compInfo.smartDevicesInComp) { -// final GenericLightDE deviceEntity = GenericLightDE( -// uniqueId: CoreUniqueId.fromUniqueString(smartDeviceInfo.id), -// cbjEntityName: CbjEntityName(smartDeviceInfo.cbjEntityName), -// roomId: CoreUniqueId.fromUniqueString(smartDeviceInfo.roomId), -// roomName: DeviceRoomName('Missing area name'), -// entityStateGRPC: EntityState( -// smartDeviceInfo.deviceTypesActions.entityStateGRPC.toString(), -// ), -// stateMassage: DeviceStateMassage(smartDeviceInfo.stateMassage), -// senderDeviceOs: DeviceSenderDeviceOs(smartDeviceInfo.senderDeviceOs), -// senderDeviceModel: -// DeviceSenderDeviceModel(smartDeviceInfo.senderDeviceModel), -// senderId: DeviceSenderId.fromUniqueString(smartDeviceInfo.senderId), -// deviceVendor: DeviceVendor( -// VendorsAndServices.vendorsAndServicesNotSupported.toString(), -// ), -// lightSwitchState: GenericLightSwitchState( -// smartDeviceInfo.deviceTypesActions.deviceAction.toString(), -// ), -// compUuid: DeviceCompUuid(smartDeviceInfo.compSpecs.compUuid), -// ); -// deviceEntityList.add(deviceEntity); -// } -// return deviceEntityList.toImmutableList(); -// } } diff --git a/lib/infrastructure/devices/device/device_repository.dart b/lib/infrastructure/devices/device/device_repository.dart index a8fa77d5a..079adbcb4 100644 --- a/lib/infrastructure/devices/device/device_repository.dart +++ b/lib/infrastructure/devices/device/device_repository.dart @@ -28,8 +28,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/gener import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:cybear_jinni/domain/device/devices_failures.dart'; import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; import 'package:cybear_jinni/infrastructure/hub_client/hub_requests_routing.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:dartz/dartz.dart'; @@ -273,10 +271,7 @@ class DeviceRepository implements IDeviceRepository { deviceModelString = iosInfo.model; } - final UserEntity currentUserEntity = - (await IUserRepository.instance.getCurrentUser()) - .getOrElse(() => throw 'Cant get current user'); - final String currentUserId = currentUserEntity.id!.getOrCrash()!; + const String currentUserId = 'user id'; deviceEntity .copyWithStateMassage('Setting up device') diff --git a/lib/infrastructure/home_user/home_user_dtos.dart b/lib/infrastructure/home_user/home_user_dtos.dart deleted file mode 100644 index 3f19593b1..000000000 --- a/lib/infrastructure/home_user/home_user_dtos.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'home_user_dtos.freezed.dart'; -part 'home_user_dtos.g.dart'; - -@freezed -abstract class HomeUserDtos implements _$HomeUserDtos { - const factory HomeUserDtos({ - required String? email, - required String? name, - required String? permission, - @JsonKey(includeFromJson: true) String? id, - }) = _HomeUserDtos; - - const HomeUserDtos._(); - - factory HomeUserDtos.fromDomain(HomeUserEntity homeUserEntity) { - return HomeUserDtos( - id: homeUserEntity.id!.getOrCrash(), - email: homeUserEntity.email!.getOrCrash(), - name: homeUserEntity.name!.getOrCrash(), - permission: homeUserEntity.permission!.getOrCrash(), - ); - } - - factory HomeUserDtos.fromJson(Map json) => - _$HomeUserDtosFromJson(json); - - factory HomeUserDtos.fromFirestore(Map doc) { - return HomeUserDtos.fromJson(doc); - } - - HomeUserEntity toDomain() { - return HomeUserEntity( - id: HomeUserUniqueId.fromUniqueString(id), - email: HomeUserEmail(email), - name: HomeUserName(name!), - permission: HomeUserPermission(permission!), - ); - } -} - -class ServerTimestampConverter implements JsonConverter { - const ServerTimestampConverter(); - - @override - DateTime fromJson(Object json) { - return DateTime.now(); - } - - @override - Object toJson(DateTime fieldValue) => fieldValue; -} diff --git a/lib/infrastructure/home_user/home_user_repository.dart b/lib/infrastructure/home_user/home_user_repository.dart deleted file mode 100644 index 22f558d1f..000000000 --- a/lib/infrastructure/home_user/home_user_repository.dart +++ /dev/null @@ -1,98 +0,0 @@ -import 'package:cybear_jinni/domain/home_user/home_user_entity.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/home_user/i_home_user_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:kt_dart/collection.dart'; - -class HomeUserRepository implements IHomeUserRepository { - @override - Future> add( - HomeUserEntity homeUserEntity, - ) async { - // try { - // final devicesDoc = await _firestore.homeDocument(); - // final deviceDtos = DeviceDtos.fromDomain(deviceEntity); - // - // await devicesDoc.devicesCollecttion - // .doc(deviceDtos.id) - // .set(deviceDtos.toJson()); - // return right(unit); - // } on PlatformException catch (e) { - // if (e.message!.contains('PERMISSION_DENIED')) { - // return left(const DevicesFailure.insufficientPermission()); - // } else { - // // log.error(e.toString()); - // return left(const DevicesFailure.unexpected()); - // } - // } - return left(const HomeUserFailures.unexpected()); - } - - @override - Future> delete( - HomeUserEntity deviceEntity, - ) async { - // try { - // final devicesDoc = await _firestore.homeDocument(); - // final deviceDtos = DeviceDtos.fromDomain(deviceEntity); - // - // await devicesDoc.devicesCollecttion.doc(deviceDtos.id).delete(); - // return right(unit); - // } on PlatformException catch (e) { - // if (e.message!.contains('PERMISSION_DENIED')) { - // return left(const DevicesFailure.insufficientPermission()); - // } else if (e.message!.contains('NOT_FOUND')) { - // return left(const DevicesFailure.unableToUpdate()); - // } else { - // // log.error(e.toString()); - // return left(const DevicesFailure.unexpected()); - // } - // } - return left(const HomeUserFailures.unexpected()); - } - - @override - Stream>> - getAllUsers() async* { - // final homeDocument = await _firestore.currentHomeDocument(); - // - // yield* homeDocument.usersCollecttion.snapshots().map( - // (snapshot) => right>( - // snapshot.docs - // .map((doc) => HomeUserDtos.fromFirestore(doc).toDomain()) - // .toImmutableList(), - // ), - // ); - // .onErrorReturnWith((e) { - // if (e is PlatformException && e.message!.contains('PERMISSION_DENIED')) { - // return left(const UserFailures.insufficientPermission()); - // } else { - // // log.error(e.toString()); - // return left(const UserFailures.unexpected()); - // } - // }) - } - - @override - Future> update( - HomeUserEntity deviceEntity, - ) async { - // try { - // final devicesDoc = await _firestore.homeDocument(); - // final deviceDtos = DeviceDtos.fromDomain(deviceEntity); - // - // await devicesDoc.devicesCollecttion - // .doc(deviceDtos.id) - // .update(deviceDtos.toJson()); - // return right(unit); - // } on PlatformException catch (e) { - // if (e.message!.contains('NOT_FOUND')) { - // return left(const DevicesFailure.unableToUpdate()); - // } else { - // // log.error(e.toString()); - // return left(const DevicesFailure.unexpected()); - // } - // } - return left(const HomeUserFailures.unexpected()); - } -} diff --git a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart b/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart deleted file mode 100644 index 08db77f67..000000000 --- a/lib/infrastructure/hub_auth_facade/hub_auth_facade.dart +++ /dev/null @@ -1,102 +0,0 @@ -import 'package:cbj_integrations_controller/domain/core/errors.dart'; -import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; -import 'package:cybear_jinni/domain/auth/auth_failure.dart'; -import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; -import 'package:cybear_jinni/domain/auth/user.dart'; -import 'package:cybear_jinni/domain/auth/value_objects.dart'; -import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/domain/user/user_value_objects.dart'; -import 'package:dartz/dartz.dart'; - -class HubAuthFacade implements IAuthFacade { - @override - Future> getSignedInUser() async => - optionOf(MUser(id: UniqueId())); - - @override - Future> getCurrentHome() async => optionOf( - MHome( - id: UniqueId.fromUniqueString( - await ILocalDbRepository2.instance.getHomeId(), - ), - ), - ); - - @override - Future> registerWithEmailAndPassword({ - required EmailAddress emailAddress, - required Password password, - }) async { - final Either - registerWithEmailAndPasswordReturnUserIdOutput = - await registerWithEmailAndPasswordReturnUserId( - emailAddress: emailAddress, - password: password, - ); - - return registerWithEmailAndPasswordReturnUserIdOutput.fold( - (l) => left(const AuthFailure.emailAlreadyInUse()), - (r) => right(unit), - ); - } - - @override - Future> registerWithEmailAndPasswordReturnUserId({ - EmailAddress? emailAddress, - Password? password, - }) async { - final emailAddressStr = emailAddress!.getOrCrash(); - - try { - // final UserCredential userCredential = - // await _firebaseAuth.createUserWithEmailAndPassword( - // email: emailAddressStr, password: passwordStr); - // - const String userIdString = '12344'; - - final String userName = - emailAddressStr.substring(0, emailAddressStr.indexOf('@')); - - final UserEntity userEntity = UserEntity( - id: UserUniqueId.fromUniqueString('12344'), - email: UserEmail(emailAddressStr), - name: UserName(userName), - firstName: UserFirstName(' '), - lastName: UserLastName(' '), - ); - - final registrarOutput = await IUserRepository.instance.create(userEntity); - registrarOutput.getOrElse(() => throw NotAuthenticatedError()); - - final MUser mUser = MUser(id: UniqueId.fromUniqueString(userIdString)); - return right(mUser); - } catch (e) { - if (e == 'email-already-in-use') { - return left(const AuthFailure.emailAlreadyInUse()); - } else { - return left(const AuthFailure.serverError()); - } - } - } - - @override - Future> signInWithEmailAndPassword({ - required EmailAddress emailAddress, - required Password password, - }) async { - try { - return right(unit); - } catch (e) { - if (e == 'wrong-password' || e == 'user-not-found') { - return left(const AuthFailure.invalidEmailAndPasswordCombination()); - } else { - return left(const AuthFailure.serverError()); - } - } - } - - @override - Future signOut() => Future.wait([]); -} diff --git a/lib/infrastructure/security_bear_client/security_bear_client_delete.dart b/lib/infrastructure/security_bear_client/security_bear_client_delete.dart deleted file mode 100644 index c49529804..000000000 --- a/lib/infrastructure/security_bear_client/security_bear_client_delete.dart +++ /dev/null @@ -1,88 +0,0 @@ -// import 'dart:async'; -// -// import 'package:cybear_jinni/infrastructure/core/gen/cbj_securityBear_server/protoc_as_dart/cbj_securityBear_server.pbgrpc.dart'; -// import 'package:cybear_jinni/infrastructure/securityBear_client/security_bear_requests_routing.dart'; -// import 'package:cybear_jinni/utils.dart'; -// import 'package:grpc/grpc.dart'; -// -// class SecurityBearClient { -// static ClientChannel? channel; -// static CbjSecurityBearClient? stub; -// -// /// Creates a stream with the SecurityBear -// static Future createStreamWithSecurityBear( -// String addressToSecurityBear, -// int securityBearPort, -// ) async { -// channel = await _createCbjSecurityBearClient(addressToSecurityBear, securityBearPort); -// stub = CbjSecurityBearClient(channel!); -// ResponseStream response; -// -// try { -// SecurityBearRequestRouting.navigateRequest(); -// -// response = -// stub!.clientTransferDevices(AppRequestsToSecurityBear.appRequestsToSecurityBearStream); -// AppRequestsToSecurityBear.appRequestsToSecurityBearStreamController.sink -// .add(ClientStatusRequests(sendingType: SendingType.firstConnection)); -// -// SecurityBearRequestsToApp.securityBearRequestsStreamController.sink.addStream(response); -// } catch (e) { -// logger.e('Caught error while stream with securityBear\n$e'); -// await channel?.shutdown(); -// } -// } -// -// /// Get SecurityBear computer and software info -// static Future getSecurityBearCompInfo( -// String addressToSecurityBear, -// int securityBearPort, -// CompSecurityBearInfo compSecurityBearInfo, -// ) async { -// // channel = await _createCbjSecurityBearClient(addressToSecurityBear, securityBearPort); -// // stub = CbjSecurityBearClient(channel!); -// CompSecurityBearInfo response; -// -// try { -// return await stub!.getCompSecurityBearInfo(compSecurityBearInfo); -// } catch (e) { -// logger.e('Caught error while trying to get SecurityBear comp info\n$e'); -// await channel?.shutdown(); -// } -// return null; -// } -// -// static Future _createCbjSecurityBearClient( -// String deviceIp, -// int securityBearPort, -// ) async { -// await channel?.shutdown(); -// return ClientChannel( -// deviceIp, -// port: securityBearPort, -// options: const ChannelOptions(credentials: ChannelCredentials.insecure()), -// ); -// } -// } -// -// /// Requests and updates from securityBear to the app -// class SecurityBearRequestsToApp { -// /// Stream controller of the requests from the securityBear -// static final securityBearRequestsStreamController = -// StreamController(); -// -// /// Stream of the requests from the securityBear -// static Stream get securityBearRequestsStream => -// securityBearRequestsStreamController.stream; -// } -// -// ///App requests for the securityBear to execute -// class AppRequestsToSecurityBear { -// /// Stream controller of the app request for the securityBear -// static final appRequestsToSecurityBearStreamController = -// StreamController(); -// -// /// Stream of the requests from the app to the securityBear -// static Stream get appRequestsToSecurityBearStream => -// appRequestsToSecurityBearStreamController.stream; -// } diff --git a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart index 00aa2c9ba..7733c8cdc 100644 --- a/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart +++ b/lib/infrastructure/security_bear_client/security_bear_connection_repository.dart @@ -2,9 +2,9 @@ import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/domain/create_home/i_create_home_repository.dart'; import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_value_objects.dart'; import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; import 'package:cybear_jinni/domain/security_bear/security_bear_entity.dart'; import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; @@ -269,8 +269,7 @@ class SecurityBearConnectionRepository ) async { try { final ManageNetworkEntity firstWifiEntityOrFailure = - (await ICreateHomeRepository.instance.getFirstWifi()) - .getOrElse(() => throw 'Error'); + ManageNetworkEntity(name: ManageWiFiName('CyBear Jinni')); final ManageNetworkEntity secondWifiEntityOrFailure = IManageNetworkRepository.manageWiFiEntity!; diff --git a/lib/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart b/lib/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart deleted file mode 100644 index b43ae1e33..000000000 --- a/lib/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'all_homes_of_user_dtos.freezed.dart'; -part 'all_homes_of_user_dtos.g.dart'; - -@freezed -abstract class AllHomesOfUserDtos implements _$AllHomesOfUserDtos { - const factory AllHomesOfUserDtos({ - required String name, - @JsonKey(includeFromJson: true) String? id, - }) = _AllHomesOfUserDtos; - - const AllHomesOfUserDtos._(); - - factory AllHomesOfUserDtos.fromDomain( - AllHomesOfUserEntity allHomesOfUserEntity, - ) { - return AllHomesOfUserDtos( - id: allHomesOfUserEntity.id!.getOrCrash(), - name: allHomesOfUserEntity.name!.getOrCrash()!, - ); - } - - factory AllHomesOfUserDtos.fromJson(Map json) => - _$AllHomesOfUserDtosFromJson(json); - - factory AllHomesOfUserDtos.fromFirestore(Map doc) { - return AllHomesOfUserDtos.fromJson(doc); - // .copyWith(id: doc.id); - } - - AllHomesOfUserEntity toDomain() { - return AllHomesOfUserEntity( - id: AllHomesOfUserUniqueId.fromUniqueString(id), - name: AllHomesOfUserName(name), - ); - } -} - -class ServerTimestampConverter implements JsonConverter { - const ServerTimestampConverter(); - - @override - DateTime fromJson(Object json) { - return DateTime.now(); - } - - @override - Object toJson(DateTime fieldValue) => fieldValue; -} diff --git a/lib/infrastructure/user/user_dtos.dart b/lib/infrastructure/user/user_dtos.dart deleted file mode 100644 index 7498f227e..000000000 --- a/lib/infrastructure/user/user_dtos.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/domain/user/user_value_objects.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'user_dtos.freezed.dart'; -part 'user_dtos.g.dart'; - -@freezed -abstract class UserDtos implements _$UserDtos { - const factory UserDtos({ - required String email, - required String name, - @JsonKey(includeFromJson: true) String? id, - String? firstName, - String? lastName, - }) = _UserDtos; - - const UserDtos._(); - - factory UserDtos.fromDomain(UserEntity userEntity) { - return UserDtos( - id: userEntity.id!.getOrCrash(), - email: userEntity.email!.getOrCrash(), - name: userEntity.name!.getOrCrash(), - firstName: userEntity.firstName!.getOrCrash(), - lastName: userEntity.lastName!.getOrCrash(), - ); - } - - factory UserDtos.fromJson(Map json) => - _$UserDtosFromJson(json); - - factory UserDtos.fromFirestore(Map doc) { - return UserDtos.fromJson(doc); - // .copyWith(id: doc.id); - } - - UserEntity toDomain() { - return UserEntity( - id: UserUniqueId.fromUniqueString(id), - email: UserEmail(email), - name: UserName(name), - firstName: UserFirstName(firstName!), - lastName: UserLastName(lastName!), - ); - } -} - -class ServerTimestampConverter implements JsonConverter { - const ServerTimestampConverter(); - - @override - DateTime fromJson(Object json) { - return DateTime.now(); - } - - @override - Object toJson(DateTime fieldValue) => fieldValue; -} diff --git a/lib/infrastructure/user/user_repository.dart b/lib/infrastructure/user/user_repository.dart deleted file mode 100644 index e5b6fa575..000000000 --- a/lib/infrastructure/user/user_repository.dart +++ /dev/null @@ -1,161 +0,0 @@ -import 'package:cbj_integrations_controller/domain/core/errors.dart'; -import 'package:cybear_jinni/domain/auth/i_auth_facade.dart'; -import 'package:cybear_jinni/domain/home_user/home_user_failures.dart'; -import 'package:cybear_jinni/domain/local_db/i_local_db_repository2.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_entity.dart'; -import 'package:cybear_jinni/domain/user/all_homes_of_user/all_homes_of_user_failures.dart'; -import 'package:cybear_jinni/domain/user/i_user_repository.dart'; -import 'package:cybear_jinni/domain/user/user_entity.dart'; -import 'package:cybear_jinni/infrastructure/user/all_homes_of_user_entity/all_homes_of_user_dtos.dart'; -import 'package:cybear_jinni/infrastructure/user/user_dtos.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/services.dart'; -import 'package:kt_dart/kt.dart'; - -class UserRepository implements IUserRepository { - @override - Future> create(UserEntity userEntity) async { - try { - UserDtos.fromDomain(userEntity); - - return right(unit); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const HomeUserFailures.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(const HomeUserFailures.unexpected()); - } - } - } - - @override - Future> getCurrentUser() async { - try { - // final userCollec = await _firestore.usersCollection(); - - (await IAuthFacade.instance.getSignedInUser()) - .getOrElse(() => throw NotAuthenticatedError()) - .id - .getOrCrash(); - - // final DocumentSnapshot userDocumentS = await userCollec.doc(userId).get(); - - // final String name = userDocumentS.get('name').toString(); - // final String email = userDocumentS.get('email').toString(); - - // return right(UserEntity( - // id: UserUniqueId.fromUniqueString(userId), - // email: UserEmail(email), - // name: UserName(name), - // )); - } on PlatformException catch (e) { - if (e.message!.contains('PERMISSION_DENIED')) { - return left(const HomeUserFailures.insufficientPermission()); - } else { - // log.error(e.toString()); - return left(const HomeUserFailures.unexpected()); - } - } - return left(const HomeUserFailures.unexpected()); - } - - @override - Future> addHome( - UserEntity userEntity, - AllHomesOfUserEntity allHomesOfUserEntity, - ) async { - try { - // final usersCollection = await _firestore.usersCollection(); - // final homeCollection = await _firestore.homeCollection(); - - final String homeId = allHomesOfUserEntity.id!.getOrCrash()!; - - // final userInHomeRef = - // homeCollection.doc(homeId).usersCollecttion.doc(userId); - // final homeDoc = await userInHomeRef.get(); - // - // if (!homeDoc.exists) { - // return left(const HomeUserFailures.homeDoesNotExist()); - // } - // - AllHomesOfUserDtos.fromDomain(allHomesOfUserEntity); - // - // await usersCollection - // .doc(userId) - // .usersHomesCollecttion - // .doc(homeId) - // .set(homeUserDtos.toJson()); - // - await ILocalDbRepository2.instance.setHomeId(homeId); - - return right(unit); - } catch (e) { - return left(const HomeUserFailures.unexpected()); - } - } - - @override - Future> delete(UserEntity deviceEntity) { - // TODO: implement delete - throw UnimplementedError(); - } - - @override - Future> update(UserEntity deviceEntity) { - // TODO: implement update - throw UnimplementedError(); - } - - @override - Stream>> - watchAll() async* { - // final devicesDoc = await _firestore.currentUserDocument(); - - // yield* devicesDoc.usersHomesCollecttion.snapshots().map( - // (snapshot) => - // right>( - // snapshot.docs - // .map((doc) => AllHomesOfUserDtos.fromFirestore(doc).toDomain()) - // .toImmutableList(), - // ), - // ); - // .onErrorReturnWith((e) { - // if (e is PlatformException && e.message!.contains('PERMISSION_DENIED')) { - // return left(const AllHomesOfUserFailures.insufficientPermission()); - // } else { - // // log.error(e.toString()); - // return left(const AllHomesOfUserFailures.unexpected()); - // } - // }); - } - - @override - Future> joinExistingHome( - AllHomesOfUserEntity allHomesOfUserEntity, - ) async { - try { - // final homeCollection = await _firestore.homeCollection(); - - (await IAuthFacade.instance.getSignedInUser()) - .getOrElse(() => throw NotAuthenticatedError()) - .id - .getOrCrash(); - final String homeId = allHomesOfUserEntity.id!.getOrCrash()!; - - // final userInHomeRef = - // homeCollection.doc(homeId).usersCollecttion.doc(userId); - // final homeDoc = await userInHomeRef.get(); - // - // if (!homeDoc.exists) { - // return left(const HomeUserFailures.homeDoesNotExist()); - // } - - await ILocalDbRepository2.instance.setHomeId(homeId); - - return right(unit); - } catch (e) { - return left(const HomeUserFailures.unexpected()); - } - } -} From dce6db2adc8f562d7f96b63b3a75d2cc9eaa17eb Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 17:40:35 +0200 Subject: [PATCH 13/15] Continue progress moving from bloc to atom's architecture --- .../blinds_actor/blinds_actor_bloc.dart | 75 --- .../blinds_actor/blinds_actor_event.dart | 23 - .../blinds_actor/blinds_actor_state.dart | 13 - .../blinds_watcher/blinds_watcher_bloc.dart | 59 -- .../blinds_watcher/blinds_watcher_event.dart | 10 - .../blinds_watcher/blinds_watcher_state.dart | 17 - .../boilers_actor/boilers_actor_bloc.dart | 61 --- .../boilers_actor/boilers_actor_event.dart | 19 - .../boilers_actor/boilers_actor_state.dart | 13 - .../boilers_watcher/boilers_watcher_bloc.dart | 60 -- .../boilers_watcher_event.dart | 10 - .../boilers_watcher_state.dart | 17 - lib/application/cbj_comp/cbj_comp_bloc.dart | 109 ---- lib/application/cbj_comp/cbj_comp_event.dart | 17 - lib/application/cbj_comp/cbj_comp_state.dart | 17 - .../configure_new_cbj_comp_bloc.dart | 321 ----------- .../configure_new_cbj_comp_event.dart | 39 -- .../configure_new_cbj_comp_state.dart | 14 - .../lights_actor/lights_actor_bloc.dart | 59 -- .../lights_actor/lights_actor_event.dart | 18 - .../lights_actor/lights_actor_state.dart | 13 - .../lights_watcher/lights_watcher_bloc.dart | 57 -- .../lights_watcher/lights_watcher_event.dart | 10 - .../lights_watcher/lights_watcher_state.dart | 17 - .../printers_actor/printers_actor_bloc.dart | 93 ---- .../printers_actor/printers_actor_event.dart | 29 - .../printers_actor/printers_actor_state.dart | 14 - .../printers_watcher_bloc.dart | 60 -- .../printers_watcher_event.dart | 10 - .../printers_watcher_state.dart | 18 - .../room_sign_in_form_bloc.dart | 182 ------- .../room_sign_in_form_event.dart | 34 -- .../room_sign_in_form_state.dart | 42 -- lib/application/scene/scene_bloc.dart | 38 -- lib/application/scene/scene_event.dart | 12 - lib/application/scene/scene_state.dart | 14 - .../security_camera_actor_bloc.dart | 97 ---- .../security_camera_actor_event.dart | 30 - .../security_camera_actor_state.dart | 15 - .../security_camera_watcher_bloc.dart | 59 -- .../security_camera_watcher_event.dart | 10 - .../security_camera_watcher_state.dart | 19 - .../smart_computers_actor_bloc.dart | 90 --- .../smart_computers_actor_event.dart | 29 - .../smart_computers_actor_state.dart | 14 - .../smart_computer_watcher_bloc.dart | 60 -- .../smart_computer_watcher_event.dart | 10 - .../smart_computer_watcher_state.dart | 19 - .../smart_plug_toggle_bloc.dart | 84 --- .../smart_plug_toggle_event.dart | 17 - .../smart_plug_toggle_state.dart | 16 - .../smart_plugs_actor_bloc.dart | 61 --- .../smart_plugs_actor_event.dart | 19 - .../smart_plugs_actor_state.dart | 14 - .../smart_plugs_watcher_bloc.dart | 60 -- .../smart_plugs_watcher_event.dart | 10 - .../smart_plugs_watcher_state.dart | 18 - .../smart_tv_actor/smart_tv_actor_bloc.dart | 145 ----- .../smart_tv_actor/smart_tv_actor_event.dart | 52 -- .../smart_tv_actor/smart_tv_actor_state.dart | 13 - .../smart_tv_watcher_bloc.dart | 61 --- .../smart_tv_watcher_event.dart | 10 - .../smart_tv_watcher_state.dart | 17 - .../switch_toggle/switch_toggle_bloc.dart | 83 --- .../switch_toggle/switch_toggle_event.dart | 17 - .../switch_toggle/switch_toggle_state.dart | 15 - .../switches_actor/switches_actor_bloc.dart | 60 -- .../switches_actor/switches_actor_event.dart | 19 - .../switches_actor/switches_actor_state.dart | 14 - .../switches_watcher_bloc.dart | 60 -- .../switches_watcher_event.dart | 10 - .../switches_watcher_state.dart | 18 - .../devices/device/device_repository.dart | 17 +- .../computer_connection_check_page.dart | 11 +- .../computer_connection_check_widget.dart | 341 ++++++++---- .../configure_new_cbj_comp_page.dart | 9 +- .../configure_new_cbj_comp_widget.dart | 312 +++++++---- .../scan_for_new_cbj_comps_page.dart | 47 +- .../scan_for_new_cbj_comps_widget.dart | 140 +++-- .../pages/add_new_room/add_new_room_page.dart | 8 +- .../widgets/add_new_room_form.dart | 303 ++++++----- .../change_room_for_devices_page.dart | 8 +- .../change_room_for_devices_widget.dart | 302 +++++++---- .../blinds/rooms_blinds_page.dart | 5 - .../blinds/widgets/blind_widget.dart | 259 +++++---- .../blinds/widgets/room_blinds.dart | 8 +- .../blinds/widgets/rooms_blinds_widget.dart | 232 ++++---- .../boilers/rooms_boilers_page.dart | 5 - .../boilers/widgets/boilers_widget.dart | 115 ++-- .../boilers/widgets/room_boilers.dart | 13 +- .../boilers/widgets/rooms_boilers_widget.dart | 231 ++++---- .../lights/rooms_lights_page.dart | 5 - .../lights/widgets/rooms_lights_widget.dart | 239 ++++---- .../printers/rooms_printers_page.dart | 5 - .../printers/widgets/printer_widget.dart | 116 ++-- .../printers/widgets/room_printers.dart | 8 +- .../widgets/rooms_printers_widget.dart | 230 ++++---- .../rooms_smart_computers_page.dart | 5 - .../widgets/room_smart_computers.dart | 8 +- .../widgets/rooms_smart_computers_widget.dart | 233 ++++---- .../widgets/smart_computer_widget.dart | 180 +++--- .../smart_plugs/rooms_smart_plugs_page.dart | 5 - .../smart_plugs/widgets/room_smart_plugs.dart | 8 +- .../widgets/rooms_smart_plugs_widget.dart | 232 ++++---- .../widgets/smart_plugs_widget.dart | 127 +++-- .../smart_tv/rooms_smart_tvs_page.dart | 5 - .../smart_tv/widgets/open_url_widget.dart | 19 +- .../smart_tv/widgets/room_smart_tvs.dart | 8 +- .../widgets/rooms_smart_tvs_widget.dart | 234 ++++---- .../smart_tv/widgets/smart_tv_widget.dart | 512 +++++++++--------- .../switches/rooms_switches_page.dart | 5 - .../switches/widgets/room_switches.dart | 8 +- .../widgets/rooms_switches_widget.dart | 235 ++++---- .../switches/widgets/switches_widget.dart | 112 ++-- .../blinds_in_the_room.dart | 176 +++--- .../lights_in_the_room_block.dart | 198 +++---- .../smart_plug_in_the_room_block.dart | 161 +++--- .../switches_in_the_room_block.dart | 143 ++--- .../rooms_widgets/rom_widget.dart | 184 +++---- .../scenes/widgets/folder_of_scenes.dart | 15 +- .../pages/scenes/widgets/scene_widget.dart | 135 ++--- 121 files changed, 3219 insertions(+), 5657 deletions(-) delete mode 100644 lib/application/blinds/blinds_actor/blinds_actor_bloc.dart delete mode 100644 lib/application/blinds/blinds_actor/blinds_actor_event.dart delete mode 100644 lib/application/blinds/blinds_actor/blinds_actor_state.dart delete mode 100644 lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart delete mode 100644 lib/application/blinds/blinds_watcher/blinds_watcher_event.dart delete mode 100644 lib/application/blinds/blinds_watcher/blinds_watcher_state.dart delete mode 100644 lib/application/boilers/boilers_actor/boilers_actor_bloc.dart delete mode 100644 lib/application/boilers/boilers_actor/boilers_actor_event.dart delete mode 100644 lib/application/boilers/boilers_actor/boilers_actor_state.dart delete mode 100644 lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart delete mode 100644 lib/application/boilers/boilers_watcher/boilers_watcher_event.dart delete mode 100644 lib/application/boilers/boilers_watcher/boilers_watcher_state.dart delete mode 100644 lib/application/cbj_comp/cbj_comp_bloc.dart delete mode 100644 lib/application/cbj_comp/cbj_comp_event.dart delete mode 100644 lib/application/cbj_comp/cbj_comp_state.dart delete mode 100644 lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart delete mode 100644 lib/application/configure_new_cbj_comp/configure_new_cbj_comp_event.dart delete mode 100644 lib/application/configure_new_cbj_comp/configure_new_cbj_comp_state.dart delete mode 100644 lib/application/lights/lights_actor/lights_actor_bloc.dart delete mode 100644 lib/application/lights/lights_actor/lights_actor_event.dart delete mode 100644 lib/application/lights/lights_actor/lights_actor_state.dart delete mode 100644 lib/application/lights/lights_watcher/lights_watcher_bloc.dart delete mode 100644 lib/application/lights/lights_watcher/lights_watcher_event.dart delete mode 100644 lib/application/lights/lights_watcher/lights_watcher_state.dart delete mode 100644 lib/application/printers/printers_actor/printers_actor_bloc.dart delete mode 100644 lib/application/printers/printers_actor/printers_actor_event.dart delete mode 100644 lib/application/printers/printers_actor/printers_actor_state.dart delete mode 100644 lib/application/printers/printers_watcher/printers_watcher_bloc.dart delete mode 100644 lib/application/printers/printers_watcher/printers_watcher_event.dart delete mode 100644 lib/application/printers/printers_watcher/printers_watcher_state.dart delete mode 100644 lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart delete mode 100644 lib/application/room/create_new_room_form/room_sign_in_form_event.dart delete mode 100644 lib/application/room/create_new_room_form/room_sign_in_form_state.dart delete mode 100644 lib/application/scene/scene_bloc.dart delete mode 100644 lib/application/scene/scene_event.dart delete mode 100644 lib/application/scene/scene_state.dart delete mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart delete mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart delete mode 100644 lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart delete mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart delete mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart delete mode 100644 lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart delete mode 100644 lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart delete mode 100644 lib/application/smart_computers/smart_computers_actor/smart_computers_actor_event.dart delete mode 100644 lib/application/smart_computers/smart_computers_actor/smart_computers_actor_state.dart delete mode 100644 lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart delete mode 100644 lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_event.dart delete mode 100644 lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_state.dart delete mode 100644 lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart delete mode 100644 lib/application/smart_plug_toggle/smart_plug_toggle_event.dart delete mode 100644 lib/application/smart_plug_toggle/smart_plug_toggle_state.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_event.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_state.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_event.dart delete mode 100644 lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_state.dart delete mode 100644 lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart delete mode 100644 lib/application/smart_tv/smart_tv_actor/smart_tv_actor_event.dart delete mode 100644 lib/application/smart_tv/smart_tv_actor/smart_tv_actor_state.dart delete mode 100644 lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart delete mode 100644 lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_event.dart delete mode 100644 lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_state.dart delete mode 100644 lib/application/switch_toggle/switch_toggle_bloc.dart delete mode 100644 lib/application/switch_toggle/switch_toggle_event.dart delete mode 100644 lib/application/switch_toggle/switch_toggle_state.dart delete mode 100644 lib/application/switches/switches_actor/switches_actor_bloc.dart delete mode 100644 lib/application/switches/switches_actor/switches_actor_event.dart delete mode 100644 lib/application/switches/switches_actor/switches_actor_state.dart delete mode 100644 lib/application/switches/switches_watcher/switches_watcher_bloc.dart delete mode 100644 lib/application/switches/switches_watcher/switches_watcher_event.dart delete mode 100644 lib/application/switches/switches_watcher/switches_watcher_state.dart diff --git a/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart b/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart deleted file mode 100644 index a134fb3ac..000000000 --- a/lib/application/blinds/blinds_actor/blinds_actor_bloc.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'blinds_actor_bloc.freezed.dart'; -part 'blinds_actor_event.dart'; -part 'blinds_actor_state.dart'; - -@injectable -class BlindsActorBloc extends Bloc { - BlindsActorBloc() : super(const BlindsActorState.initial()) { - on(_deleted); - on(_initialized); - on(_moveUpAllBlinds); - on(_stopAllBlinds); - on(_moveDownAllBlinds); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _moveUpAllBlinds( - MoveUpAllBlinds event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Pulling_Up_all_blinds'.tr(), - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .moveUpStateDevices(devicesId: event.blindsIdToTurnUp); - } - - Future _stopAllBlinds( - StopAllBlinds event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Stopping_all_blinds'.tr(), - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .stopStateDevices(devicesId: event.blindsIdToStop); - } - - Future _moveDownAllBlinds( - MoveDownAllBlinds event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Pulling_down_all_blinds'.tr(), - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .moveDownStateDevices(devicesId: event.blindsIdToTurnDown); - } -} diff --git a/lib/application/blinds/blinds_actor/blinds_actor_event.dart b/lib/application/blinds/blinds_actor/blinds_actor_event.dart deleted file mode 100644 index 41156e10c..000000000 --- a/lib/application/blinds/blinds_actor/blinds_actor_event.dart +++ /dev/null @@ -1,23 +0,0 @@ -part of 'blinds_actor_bloc.dart'; - -@freezed -class BlindsActorEvent with _$BlindsActorEvent { - const factory BlindsActorEvent.initialized() = Initialized; - - const factory BlindsActorEvent.moveUpAllBlinds( - List? blindsIdToTurnUp, - BuildContext context, - ) = MoveUpAllBlinds; - - const factory BlindsActorEvent.stopAllBlinds( - List? blindsIdToStop, - BuildContext context, - ) = StopAllBlinds; - - const factory BlindsActorEvent.moveDownAllBlinds( - List? blindsIdToTurnDown, - BuildContext context, - ) = MoveDownAllBlinds; - - const factory BlindsActorEvent.deleted(GenericLightDE deviceEntity) = Deleted; -} diff --git a/lib/application/blinds/blinds_actor/blinds_actor_state.dart b/lib/application/blinds/blinds_actor/blinds_actor_state.dart deleted file mode 100644 index ebc52502d..000000000 --- a/lib/application/blinds/blinds_actor/blinds_actor_state.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'blinds_actor_bloc.dart'; - -@freezed -class BlindsActorState with _$BlindsActorState { - const factory BlindsActorState.initial() = _Initial; - - const factory BlindsActorState.actionInProgress() = _ActionInProgress; - - const factory BlindsActorState.deleteFailure(DevicesFailure devicesFailure) = - _DeleteFailure; - - const factory BlindsActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart b/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart deleted file mode 100644 index cf4b28c71..000000000 --- a/lib/application/blinds/blinds_watcher/blinds_watcher_bloc.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'blinds_watcher_bloc.freezed.dart'; -part 'blinds_watcher_event.dart'; -part 'blinds_watcher_state.dart'; - -@injectable -class BlindsWatcherBloc extends Bloc { - BlindsWatcherBloc() - : super(BlindsWatcherState.initial()) { - on(_watchAllStarted); - on(_blindsReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllBlindsStarted event, - Emitter emit, - ) async { - emit(const BlindsWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchBlinds().listen( - (eventWatch) => add(BlindsWatcherEvent.blindsReceived(eventWatch)), - ); - } - - Future _blindsReceived( - BlindsReceived event, - Emitter emit, - ) async { - emit(const BlindsWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => BlindsWatcherState.loadFailure(f), - (d) => BlindsWatcherState.loadSuccess( - d.map((v) => v! as GenericBlindsDE).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/blinds/blinds_watcher/blinds_watcher_event.dart b/lib/application/blinds/blinds_watcher/blinds_watcher_event.dart deleted file mode 100644 index c226a27d0..000000000 --- a/lib/application/blinds/blinds_watcher/blinds_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'blinds_watcher_bloc.dart'; - -@freezed -class BlindsWatcherEvent with _$BlindsWatcherEvent { - const factory BlindsWatcherEvent.watchAllStarted() = WatchAllBlindsStarted; - - const factory BlindsWatcherEvent.blindsReceived( - Either> failureOrDevices, - ) = BlindsReceived; -} diff --git a/lib/application/blinds/blinds_watcher/blinds_watcher_state.dart b/lib/application/blinds/blinds_watcher/blinds_watcher_state.dart deleted file mode 100644 index 113bda717..000000000 --- a/lib/application/blinds/blinds_watcher/blinds_watcher_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'blinds_watcher_bloc.dart'; - -@freezed -class BlindsWatcherState with _$BlindsWatcherState { - factory BlindsWatcherState.initial() = Initial; - - const factory BlindsWatcherState.loadInProgress() = LoadInProgress; - - const factory BlindsWatcherState.loadSuccess( - KtList devices, - ) = LoadSuccess; - - const factory BlindsWatcherState.loadFailure(DevicesFailure devicesFailure) = - LoadFailure; - - const factory BlindsWatcherState.blindError() = BlindError; -} diff --git a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart b/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart deleted file mode 100644 index 59fc4ff97..000000000 --- a/lib/application/boilers/boilers_actor/boilers_actor_bloc.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'boilers_actor_bloc.freezed.dart'; -part 'boilers_actor_event.dart'; -part 'boilers_actor_state.dart'; - -@injectable -class BoilersActorBloc extends Bloc { - BoilersActorBloc() : super(const BoilersActorState.initial()) { - on(_deleted); - on(_initialized); - on(_turnOnAllBoilers); - on(_turnOffAllBoilers); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _turnOnAllBoilers( - TurnOnAllBoilers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning_On_boiler'.tr(), - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.boilersIdToTurnUp); - } - - Future _turnOffAllBoilers( - TurnOffAllBoilers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning_Off_boiler'.tr(), - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOffDevices(devicesId: event.boilersIdToTurnOff); - } -} diff --git a/lib/application/boilers/boilers_actor/boilers_actor_event.dart b/lib/application/boilers/boilers_actor/boilers_actor_event.dart deleted file mode 100644 index 77436deba..000000000 --- a/lib/application/boilers/boilers_actor/boilers_actor_event.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'boilers_actor_bloc.dart'; - -@freezed -class BoilersActorEvent with _$BoilersActorEvent { - const factory BoilersActorEvent.initialized() = Initialized; - - const factory BoilersActorEvent.turnOnAllBoilers( - List? boilersIdToTurnUp, - BuildContext context, - ) = TurnOnAllBoilers; - - const factory BoilersActorEvent.turnOffAllBoilers( - List? boilersIdToTurnOff, - BuildContext context, - ) = TurnOffAllBoilers; - - const factory BoilersActorEvent.deleted(GenericBoilerDE deviceEntity) = - Deleted; -} diff --git a/lib/application/boilers/boilers_actor/boilers_actor_state.dart b/lib/application/boilers/boilers_actor/boilers_actor_state.dart deleted file mode 100644 index f7f48501c..000000000 --- a/lib/application/boilers/boilers_actor/boilers_actor_state.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'boilers_actor_bloc.dart'; - -@freezed -class BoilersActorState with _$BoilersActorState { - const factory BoilersActorState.initial() = _Initial; - - const factory BoilersActorState.actionInProgress() = _ActionInProgress; - - const factory BoilersActorState.deleteFailure(DevicesFailure devicesFailure) = - _DeleteFailure; - - const factory BoilersActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart b/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart deleted file mode 100644 index 484b5c0f0..000000000 --- a/lib/application/boilers/boilers_watcher/boilers_watcher_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'boilers_watcher_bloc.freezed.dart'; -part 'boilers_watcher_event.dart'; -part 'boilers_watcher_state.dart'; - -@injectable -class BoilersWatcherBloc - extends Bloc { - BoilersWatcherBloc() - : super(BoilersWatcherState.initial()) { - on(_watchAllStarted); - on(_boilersReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllBoilersStarted event, - Emitter emit, - ) async { - emit(const BoilersWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchBoilers().listen( - (eventWatch) => add(BoilersWatcherEvent.boilersReceived(eventWatch)), - ); - } - - Future _boilersReceived( - BoilersReceived event, - Emitter emit, - ) async { - emit(const BoilersWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => BoilersWatcherState.loadFailure(f), - (d) => BoilersWatcherState.loadSuccess( - d.map((v) => v! as GenericBoilerDE).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/boilers/boilers_watcher/boilers_watcher_event.dart b/lib/application/boilers/boilers_watcher/boilers_watcher_event.dart deleted file mode 100644 index 1116071ec..000000000 --- a/lib/application/boilers/boilers_watcher/boilers_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'boilers_watcher_bloc.dart'; - -@freezed -class BoilersWatcherEvent with _$BoilersWatcherEvent { - const factory BoilersWatcherEvent.watchAllStarted() = WatchAllBoilersStarted; - - const factory BoilersWatcherEvent.boilersReceived( - Either> failureOrDevices, - ) = BoilersReceived; -} diff --git a/lib/application/boilers/boilers_watcher/boilers_watcher_state.dart b/lib/application/boilers/boilers_watcher/boilers_watcher_state.dart deleted file mode 100644 index d7278c0d7..000000000 --- a/lib/application/boilers/boilers_watcher/boilers_watcher_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'boilers_watcher_bloc.dart'; - -@freezed -class BoilersWatcherState with _$BoilersWatcherState { - factory BoilersWatcherState.initial() = _Initial; - - const factory BoilersWatcherState.loadInProgress() = _LoadInProgress; - - const factory BoilersWatcherState.loadSuccess( - KtList devices, - ) = _LoadSuccess; - - const factory BoilersWatcherState.loadFailure(DevicesFailure devicesFailure) = - _loadFailure; - - const factory BoilersWatcherState.boilerError() = _BoilerError; -} diff --git a/lib/application/cbj_comp/cbj_comp_bloc.dart b/lib/application/cbj_comp/cbj_comp_bloc.dart deleted file mode 100644 index e1bdb854b..000000000 --- a/lib/application/cbj_comp/cbj_comp_bloc.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; -import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'cbj_comp_bloc.freezed.dart'; -part 'cbj_comp_event.dart'; -part 'cbj_comp_state.dart'; - -@injectable -class CBJCompBloc extends Bloc { - CBJCompBloc() : super(CBJCompState.initial()) { - on(_initialized); - on(_watchAllStarted); - on(_changeAction); - on(_compDevicesReceived); - on(_create); - } - - StreamSubscription>? - _cbjCompStreamSubscription; - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _create( - CreateDevice event, - Emitter emit, - ) async {} - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const CBJCompState.loadInProgress()); - await _cbjCompStreamSubscription?.cancel(); - _cbjCompStreamSubscription = ICBJCompRepository.instance - .getConnectedComputersIP() - .listen((failureOrCBJCompList) { - final dynamic failureOrCompListDynamic = failureOrCBJCompList.fold( - (f) => f, - (ip) => ip, - ); - - if (failureOrCompListDynamic == CBJCompFailure) { - emit( - CBJCompState.loadFailure( - failureOrCompListDynamic as CBJCompFailure, - ), - ); - } else { - //TODO: Call close app server function if Security Bear ip got found - add(CBJCompEvent.compDevicesReceived(failureOrCBJCompList)); - } - }); - } - - Future _compDevicesReceived( - CompDevicesReceived event, - Emitter emit, - ) async { - emit(const CBJCompState.loadInProgress()); - - final dynamic failureOrCompListDynamic = event.failureOrCBJCompList.fold( - (f) => f, - (ip) => ip, - ); - - if (failureOrCompListDynamic == CBJCompFailure) { - emit( - CBJCompState.loadFailure( - failureOrCompListDynamic as CBJCompFailure, - ), - ); - } else { - final String ipAsString = failureOrCompListDynamic as String; - emit(CBJCompState.loadSuccess(ipAsString)); - } - } - - Future _changeAction( - ChangeState event, - Emitter emit, - ) async { - final actionResult = - await ICBJCompRepository.instance.updateCompInfo(event.cBJCompEntity); - - emit( - actionResult.fold( - (f) => CBJCompState.loadFailure(f), - (r) => const CBJCompState.loadSuccessTemp(), - ), - ); - } - - @override - Future close() async { - await _cbjCompStreamSubscription?.cancel(); - await ICBJCompRepository.instance.shutdownServer(); - return super.close(); - } -} diff --git a/lib/application/cbj_comp/cbj_comp_event.dart b/lib/application/cbj_comp/cbj_comp_event.dart deleted file mode 100644 index ef590d23e..000000000 --- a/lib/application/cbj_comp/cbj_comp_event.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'cbj_comp_bloc.dart'; - -@freezed -class CBJCompEvent with _$CBJCompEvent { - const factory CBJCompEvent.initialized() = Initialized; - - const factory CBJCompEvent.watchAllStarted() = WatchAllStarted; - - const factory CBJCompEvent.changeAction(CBJCompEntity cBJCompEntity) = - ChangeState; - - const factory CBJCompEvent.compDevicesReceived( - Either failureOrCBJCompList, - ) = CompDevicesReceived; - - const factory CBJCompEvent.create(CBJCompEntity cBJCompEntity) = CreateDevice; -} diff --git a/lib/application/cbj_comp/cbj_comp_state.dart b/lib/application/cbj_comp/cbj_comp_state.dart deleted file mode 100644 index df7f280a6..000000000 --- a/lib/application/cbj_comp/cbj_comp_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'cbj_comp_bloc.dart'; - -@freezed -class CBJCompState with _$CBJCompState { - factory CBJCompState.initial() = _Initial; - - const factory CBJCompState.loadInProgress() = _LoadInProgress; - - const factory CBJCompState.loadSuccess(String securityBearIp) = _LoadSuccess; - - const factory CBJCompState.loadSuccessTemp() = _LoadSuccessTemp; - - const factory CBJCompState.loadFailure(CBJCompFailure cBJCompFailure) = - _loadFailure; - - const factory CBJCompState.error() = Error; -} diff --git a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart deleted file mode 100644 index 9a7dabe28..000000000 --- a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart +++ /dev/null @@ -1,321 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; -import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; -import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; -import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; -import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; -import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; -import 'package:cybear_jinni/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart'; -import 'package:cybear_jinni/utils.dart'; -import 'package:dartz/dartz.dart'; -import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/widgets.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; -import 'package:wifi_iot/wifi_iot.dart'; -import 'package:wifi_scan/wifi_scan.dart'; - -part 'configure_new_cbj_comp_bloc.freezed.dart'; -part 'configure_new_cbj_comp_event.dart'; -part 'configure_new_cbj_comp_state.dart'; - -@injectable -class ConfigureNewCbjCompBloc - extends Bloc { - ConfigureNewCbjCompBloc() : super(const ConfigureNewCbjCompState.initial()) { - on(_initialized); - on(_deleted); - on(_setupNewDevice); - on(_saveDevicesToCloud); - on(_saveDevicesToComputer); - on(_sendFirebaseInformation); - on(_sendHotSpotInformation); - on( - _checkOperationsCompletedSuccessfully, - ); - on(_checkConnectedToWiFiNetwork); - on(_searchIfHubOnTheSameWifiNetwork); - } - - /// Progress counter for setting new devices - double progressPercent = 0.0; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const ConfigureNewCbjCompState.initial()); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _setupNewDevice( - SetupNewDevice event, - Emitter emit, - ) async { - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - - final CBJCompEntity compUpdatedData = newCBJCompEntity( - event.cBJCompEntity, - event.textEditingController, - ); - progressPercent += 0.1; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - add(ConfigureNewCbjCompEvent.saveDevicesToCloud(compUpdatedData)); - // - // final bool error = await InitialNewDevice(compUpdatedData); - // if (!error) { - // progressPercent += 0.1; - // yield ConfigureNewCbjCompState.actionInProgress(progressPercent); - // add(ConfigureNewCbjCompEvent.saveDevicesToCloud(compUpdatedData)); - // } else { - // yield const ConfigureNewCbjCompState.errorInProcess(); - // } - } - - Future _saveDevicesToCloud( - SaveDevicesToCloud event, - Emitter emit, - ) async { - final CBJCompEntity compUpdatedData = event.cBJCompEntity; - bool error = false; - - final KtList devicesList = - compUpdatedData.cBJCompDevices!.getOrCrash(); - - for (final GenericLightDE device in devicesList.asList()) { - final Either createInCloudResponse = - await IDeviceRepository.instance.create(device); - - createInCloudResponse.fold( - (l) { - error = true; - }, - (r) {}, - ); - - progressPercent += 0.3 / devicesList.size; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - } - if (error) { - emit(const ConfigureNewCbjCompState.errorInProcess()); - } else { - add(ConfigureNewCbjCompEvent.saveDevicesToComputer(compUpdatedData)); - } - } - - Future _saveDevicesToComputer( - SaveDevicesToComputer event, - Emitter emit, - ) async { - final CBJCompEntity compUpdatedData = event.cBJCompEntity; - - final bool error = await initialNewDevice(compUpdatedData); - if (!error) { - progressPercent += 0.1; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - add(ConfigureNewCbjCompEvent.sendHotSpotInformation(compUpdatedData)); - } else { - emit(const ConfigureNewCbjCompState.errorInProcess()); - } - } - - Future _sendFirebaseInformation( - SendFirebaseInformation event, - Emitter emit, - ) async { - event.cBJCompEntity; - - // final Either updateAllDevices = - // await _cBJCompRepository - // .setFirebaseAccountInformation(compUpdatedData); - // - // updateAllDevices.fold( - // (l) { - // error = true; - // }, - // (r) => add( - // ConfigureNewCbjCompEvent.checkOperationsCompletedSuccessfully( - // compUpdatedData, - // ), - // ), - // ); - - progressPercent += 0.3; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - } - - Future _sendHotSpotInformation( - SendHotSpotInformation event, - Emitter emit, - ) async { - progressPercent += 0.3; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - - final CBJCompEntity compUpdatedData = event.cBJCompEntity; - final Either setSecurityBearWiFi = - await ISecurityBearConnectionRepository.instance - .setSecurityBearWiFiInformation(compUpdatedData); - - setSecurityBearWiFi.fold( - (l) { - emit(const ConfigureNewCbjCompState.errorInProcess()); - return; - }, - (r) { - progressPercent += 0.5; - WiFiForIoTPlugin.disconnect(); - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - // add( - // ConfigureNewCbjCompEvent.checkOperationsCompletedSuccessfully( - // compUpdatedData, - // ), - // ); - }, - ); - emit(const ConfigureNewCbjCompState.completeSuccess()); - } - - Future _checkOperationsCompletedSuccessfully( - CheckOperationsCompletedSuccessfully event, - Emitter emit, - ) async { - bool error = false; - - final CBJCompEntity compUpdatedData = event.cBJCompEntity; - final Either setSecurityBearWiFi = - await ISecurityBearConnectionRepository.instance - .setSecurityBearWiFiInformation(compUpdatedData); - - setSecurityBearWiFi.fold( - (l) { - error = true; - }, - (r) { - return; - }, - ); - if (error) { - emit(const ConfigureNewCbjCompState.errorInProcess()); - } else { - progressPercent += 0.3; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - add( - ConfigureNewCbjCompEvent.checkOperationsCompletedSuccessfully( - compUpdatedData, - ), - ); - } - } - - Future _checkConnectedToWiFiNetwork( - CheckConnectedToWiFiNetwork event, - Emitter emit, - ) async { - if ((await WiFiScan.instance.canStartScan()) == CanStartScan.yes) { - await WiFiScan.instance.startScan(); - if ((await WiFiScan.instance.canGetScannedResults()) == - CanGetScannedResults.yes) { - await WiFiScan.instance.getScannedResults(); - } - } - - bool isConnectedToWifi = false; - logger.i('Waiting_for_user_to_get_connected_to_WiFi'.tr()); - - while (true) { - isConnectedToWifi = await WiFiForIoTPlugin.isConnected(); - if (isConnectedToWifi) { - break; - } - await Future.delayed(const Duration(seconds: 10)); - } - - progressPercent += 50; - emit(ConfigureNewCbjCompState.actionInProgress(progressPercent)); - } - - Future _searchIfHubOnTheSameWifiNetwork( - SearchIfHubOnTheSameWifiNetwork event, - Emitter emit, - ) async { - int connectionTimeout = 0; - - while (true) { - connectionTimeout++; - (await ISecurityBearConnectionRepository.instance - .searchForSecurityBearInCurrentNetwork()) - .fold((l) {}, (r) { - emit(const ConfigureNewCbjCompState.completeSuccess()); - return; - }); - if (connectionTimeout == 10) { - break; - } - await Future.delayed(const Duration(seconds: 30)); - } - - emit(const ConfigureNewCbjCompState.errorInProcess()); - } - - /// Organize all the data from the text fields to updated CBJCompEntity - CBJCompEntity newCBJCompEntity( - CBJCompEntity cbjCompEntity, - Map textEditingController, - ) { - final String deviceNameFieldKey = - ConfigureNewCbjCompWidgets.deviceNameFieldKey; - final List deviceEntityList = []; - - textEditingController['allInSameRoom']!.text; - - final ManageNetworkEntity manageWiFiEntity = - IManageNetworkRepository.manageWiFiEntity!; - manageWiFiEntity.name!.getOrCrash(); - - cbjCompEntity.cBJCompDevices!.getOrCrash().asList().forEach((deviceE) { - try { - final String deviceName = textEditingController[ - '$deviceNameFieldKey/${deviceE.uniqueId.getOrCrash()}']! - .text; - deviceEntityList.add( - deviceE..cbjEntityName = CbjEntityName(deviceName), - ); - } catch (e) { - logger.w("Can't_add_unsupported_device".tr()); - } - }); - final CBJCompEntity compUpdatedData = cbjCompEntity.copyWith( - cBJCompDevices: CBJCompDevices(deviceEntityList.toImmutableList()), - ); - - return compUpdatedData; - } - - Future initialNewDevice(CBJCompEntity compUpdatedData) async { - bool error = false; - - final Either updateAllDevices = - await ICBJCompRepository.instance.firstSetup(compUpdatedData); - - updateAllDevices.fold( - (l) { - error = true; - }, - (r) {}, - ); - return error; - } -} diff --git a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_event.dart b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_event.dart deleted file mode 100644 index 9d5e691a3..000000000 --- a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_event.dart +++ /dev/null @@ -1,39 +0,0 @@ -part of 'configure_new_cbj_comp_bloc.dart'; - -@freezed -class ConfigureNewCbjCompEvent with _$ConfigureNewCbjCompEvent { - const factory ConfigureNewCbjCompEvent.initialized() = Initialized; - - const factory ConfigureNewCbjCompEvent.deleted(GenericLightDE deviceEntity) = - Deleted; - - const factory ConfigureNewCbjCompEvent.setupNewDevice( - CBJCompEntity cBJCompEntity, - Map textEditingController, - ) = SetupNewDevice; - const factory ConfigureNewCbjCompEvent.saveDevicesToCloud( - CBJCompEntity cBJCompEntity, - ) = SaveDevicesToCloud; - - const factory ConfigureNewCbjCompEvent.saveDevicesToComputer( - CBJCompEntity cBJCompEntity, - ) = SaveDevicesToComputer; - - const factory ConfigureNewCbjCompEvent.sendFirebaseInformation( - CBJCompEntity cBJCompEntity, - ) = SendFirebaseInformation; - - const factory ConfigureNewCbjCompEvent.sendHotSpotInformation( - CBJCompEntity cBJCompEntity, - ) = SendHotSpotInformation; - - const factory ConfigureNewCbjCompEvent.checkOperationsCompletedSuccessfully( - CBJCompEntity cBJCompEntity, - ) = CheckOperationsCompletedSuccessfully; - - const factory ConfigureNewCbjCompEvent.checkConnectedToWiFiNetwork() = - CheckConnectedToWiFiNetwork; - - const factory ConfigureNewCbjCompEvent.searchIfHubOnTheSameWifiNetwork() = - SearchIfHubOnTheSameWifiNetwork; -} diff --git a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_state.dart b/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_state.dart deleted file mode 100644 index c47b1e32c..000000000 --- a/lib/application/configure_new_cbj_comp/configure_new_cbj_comp_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'configure_new_cbj_comp_bloc.dart'; - -@freezed -class ConfigureNewCbjCompState with _$ConfigureNewCbjCompState { - const factory ConfigureNewCbjCompState.initial() = _Initial; - - const factory ConfigureNewCbjCompState.actionInProgress( - double progressPercentage, - ) = ActionInProgress; - - const factory ConfigureNewCbjCompState.completeSuccess() = CompleteSuccess; - - const factory ConfigureNewCbjCompState.errorInProcess() = ErrorInProcess; -} diff --git a/lib/application/lights/lights_actor/lights_actor_bloc.dart b/lib/application/lights/lights_actor/lights_actor_bloc.dart deleted file mode 100644 index 305cd771d..000000000 --- a/lib/application/lights/lights_actor/lights_actor_bloc.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'lights_actor_bloc.freezed.dart'; -part 'lights_actor_event.dart'; -part 'lights_actor_state.dart'; - -@injectable -class LightsActorBloc extends Bloc { - LightsActorBloc() : super(const LightsActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllLights); - on(_turnOnAllLights); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllLights( - TurnOffAllLights event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all lights', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOffDevices(devicesId: event.lightsIdToTurnOff); - } - - Future _turnOnAllLights( - TurnOnAllLights event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all lights', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.turnOnDevices(devicesId: event.lightsIdToTurnOn); - } -} diff --git a/lib/application/lights/lights_actor/lights_actor_event.dart b/lib/application/lights/lights_actor/lights_actor_event.dart deleted file mode 100644 index 8a56da501..000000000 --- a/lib/application/lights/lights_actor/lights_actor_event.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'lights_actor_bloc.dart'; - -@freezed -class LightsActorEvent with _$LightsActorEvent { - const factory LightsActorEvent.initialized() = Initialized; - - const factory LightsActorEvent.turnOffAllLights( - List lightsIdToTurnOff, - BuildContext context, - ) = TurnOffAllLights; - - const factory LightsActorEvent.turnOnAllLights( - List lightsIdToTurnOn, - BuildContext context, - ) = TurnOnAllLights; - - const factory LightsActorEvent.deleted(GenericLightDE deviceEntity) = Deleted; -} diff --git a/lib/application/lights/lights_actor/lights_actor_state.dart b/lib/application/lights/lights_actor/lights_actor_state.dart deleted file mode 100644 index 38cdf2312..000000000 --- a/lib/application/lights/lights_actor/lights_actor_state.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'lights_actor_bloc.dart'; - -@freezed -class LightsActorState with _$LightsActorState { - const factory LightsActorState.initial() = _Initial; - - const factory LightsActorState.actionInProgress() = _ActionInProgress; - - const factory LightsActorState.deleteFailure(DevicesFailure devicesFailure) = - _DeleteFailure; - - const factory LightsActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart b/lib/application/lights/lights_watcher/lights_watcher_bloc.dart deleted file mode 100644 index 683bccbd9..000000000 --- a/lib/application/lights/lights_watcher/lights_watcher_bloc.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'lights_watcher_bloc.freezed.dart'; -part 'lights_watcher_event.dart'; -part 'lights_watcher_state.dart'; - -@injectable -class LightsWatcherBloc extends Bloc { - LightsWatcherBloc() : super(LightsWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const LightsWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchLights().listen( - (eventWatch) => add(LightsWatcherEvent.devicesReceived(eventWatch)), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const LightsWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => LightsWatcherState.loadFailure(f), - (d) => LightsWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/lights/lights_watcher/lights_watcher_event.dart b/lib/application/lights/lights_watcher/lights_watcher_event.dart deleted file mode 100644 index 7b8835090..000000000 --- a/lib/application/lights/lights_watcher/lights_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'lights_watcher_bloc.dart'; - -@freezed -class LightsWatcherEvent with _$LightsWatcherEvent { - const factory LightsWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory LightsWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/lights/lights_watcher/lights_watcher_state.dart b/lib/application/lights/lights_watcher/lights_watcher_state.dart deleted file mode 100644 index f8da8e4e4..000000000 --- a/lib/application/lights/lights_watcher/lights_watcher_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'lights_watcher_bloc.dart'; - -@freezed -class LightsWatcherState with _$LightsWatcherState { - factory LightsWatcherState.initial() = _Initial; - - const factory LightsWatcherState.loadInProgress() = _LoadInProgress; - - const factory LightsWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory LightsWatcherState.loadFailure(DevicesFailure devicesFailure) = - _loadFailure; - - const factory LightsWatcherState.lightError() = LightError; -} diff --git a/lib/application/printers/printers_actor/printers_actor_bloc.dart b/lib/application/printers/printers_actor/printers_actor_bloc.dart deleted file mode 100644 index 23e962d0f..000000000 --- a/lib/application/printers/printers_actor/printers_actor_bloc.dart +++ /dev/null @@ -1,93 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:url_launcher/url_launcher.dart'; - -part 'printers_actor_bloc.freezed.dart'; -part 'printers_actor_event.dart'; -part 'printers_actor_state.dart'; - -@injectable -class PrintersActorBloc extends Bloc { - PrintersActorBloc() : super(const PrintersActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllPrinters); - on(_turnOnAllPrinters); - on(_openPrintersWebPage); - on(_shutdownAllPrinters); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllPrinters( - TurnOffAllPrinters event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.turnOffDevices( - devicesId: event.printersIdToTurnOff, - ); - } - - Future _turnOnAllPrinters( - TurnOnAllPrinters event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.printersIdToTurnOn); - } - - Future _openPrintersWebPage( - OpenPrintersWebPage event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Opening printers Web Page', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - final String printerIp = event.printer.deviceLastKnownIp.getOrCrash(); - launchUrl( - Uri.parse('http://$printerIp'), - mode: LaunchMode.externalApplication, - ); - } - - Future _shutdownAllPrinters( - ShutdownAllPrinters event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Suspending all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.shutdownDevices(devicesId: event.printersId); - } -} diff --git a/lib/application/printers/printers_actor/printers_actor_event.dart b/lib/application/printers/printers_actor/printers_actor_event.dart deleted file mode 100644 index 175e7eff8..000000000 --- a/lib/application/printers/printers_actor/printers_actor_event.dart +++ /dev/null @@ -1,29 +0,0 @@ -part of 'printers_actor_bloc.dart'; - -@freezed -class PrintersActorEvent with _$PrintersActorEvent { - const factory PrintersActorEvent.initialized() = Initialized; - - const factory PrintersActorEvent.turnOffAllPrinters( - List printersIdToTurnOff, - BuildContext context, - ) = TurnOffAllPrinters; - - const factory PrintersActorEvent.turnOnAllPrinters( - List printersIdToTurnOn, - BuildContext context, - ) = TurnOnAllPrinters; - - const factory PrintersActorEvent.openPrintersWebPage( - GenericPrinterDE printer, - BuildContext context, - ) = OpenPrintersWebPage; - - const factory PrintersActorEvent.shutdownAllPrinters( - List printersId, - BuildContext context, - ) = ShutdownAllPrinters; - - const factory PrintersActorEvent.deleted(GenericSwitchDE deviceEntity) = - Deleted; -} diff --git a/lib/application/printers/printers_actor/printers_actor_state.dart b/lib/application/printers/printers_actor/printers_actor_state.dart deleted file mode 100644 index 2bbab8547..000000000 --- a/lib/application/printers/printers_actor/printers_actor_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'printers_actor_bloc.dart'; - -@freezed -class PrintersActorState with _$PrintersActorState { - const factory PrintersActorState.initial() = _Initial; - - const factory PrintersActorState.actionInProgress() = _ActionInProgress; - - const factory PrintersActorState.deleteFailure( - DevicesFailure devicesFailure, - ) = _DeleteFailure; - - const factory PrintersActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart b/lib/application/printers/printers_watcher/printers_watcher_bloc.dart deleted file mode 100644 index 512595fcc..000000000 --- a/lib/application/printers/printers_watcher/printers_watcher_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'printers_watcher_bloc.freezed.dart'; -part 'printers_watcher_event.dart'; -part 'printers_watcher_state.dart'; - -@injectable -class PrintersWatcherBloc - extends Bloc { - PrintersWatcherBloc() : super(PrintersWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const PrintersWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = - IDeviceRepository.instance.watchPrinters().listen( - (eventWatch) => - add(PrintersWatcherEvent.devicesReceived(eventWatch)), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const PrintersWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => PrintersWatcherState.loadFailure(f), - (d) => PrintersWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/printers/printers_watcher/printers_watcher_event.dart b/lib/application/printers/printers_watcher/printers_watcher_event.dart deleted file mode 100644 index 6352ef122..000000000 --- a/lib/application/printers/printers_watcher/printers_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'printers_watcher_bloc.dart'; - -@freezed -class PrintersWatcherEvent with _$PrintersWatcherEvent { - const factory PrintersWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory PrintersWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/printers/printers_watcher/printers_watcher_state.dart b/lib/application/printers/printers_watcher/printers_watcher_state.dart deleted file mode 100644 index f5cbd54d7..000000000 --- a/lib/application/printers/printers_watcher/printers_watcher_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'printers_watcher_bloc.dart'; - -@freezed -class PrintersWatcherState with _$PrintersWatcherState { - factory PrintersWatcherState.initial() = _Initial; - - const factory PrintersWatcherState.loadInProgress() = _LoadInProgress; - - const factory PrintersWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory PrintersWatcherState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory PrintersWatcherState.printersError() = PrintersError; -} diff --git a/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart b/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart deleted file mode 100644 index 48769d2b3..000000000 --- a/lib/application/room/create_new_room_form/room_sign_in_form_bloc.dart +++ /dev/null @@ -1,182 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; -import 'package:cbj_integrations_controller/domain/vendors/login_abstract/core_login_failures.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'room_sign_in_form_bloc.freezed.dart'; -part 'room_sign_in_form_event.dart'; -part 'room_sign_in_form_state.dart'; - -@injectable -class RoomSignInFormBloc - extends Bloc { - RoomSignInFormBloc() - : super(RoomSignInFormState.initial()) { - on(_createRoom); - on(_changeRoomDevices); - on(_defaultNameChanged); - on(_roomTypesChanged); - on(_roomIdChanged); - on(_roomDevicesIdChanged); - on(_roomMostUsedByChanged); - on(_roomPermissionsChanged); - on(_initialized); - - add(const RoomSignInFormEvent.initialized()); - } - - - List _allRooms = []; - List _allDevices = []; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - (await IRoomRepository.instance.getAllRooms()).fold((l) => null, (r) { - _allRooms = List.from(r.iter); - }); - - (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { - _allDevices = List.from(r.iter); - }); - _allRooms.removeWhere((element) => element == null); - _allDevices.removeWhere((element) => element == null); - - emit( - state.copyWith( - allRooms: _allRooms as List, - allDevices: _allDevices as List, - ), - ); - } - - Future _changeRoomDevices( - ChangeRoomDevices event, - Emitter emit, - ) async { - final RoomEntity roomEntity = RoomEntity( - uniqueId: RoomUniqueId.fromUniqueString(state.roomUniqueId.getOrCrash()), - cbjEntityName: RoomDefaultName(state.cbjEntityName.getOrCrash()), - background: RoomBackground(state.background.getOrCrash()), - roomTypes: RoomTypes(state.roomTypes.getOrCrash()), - roomDevicesId: RoomDevicesId(state.roomDevicesId.getOrCrash()), - roomScenesId: RoomScenesId(state.roomScenesId.getOrCrash()), - roomRoutinesId: RoomRoutinesId(state.roomRoutinesId.getOrCrash()), - roomBindingsId: RoomBindingsId(state.roomBindingsId.getOrCrash()), - roomMostUsedBy: RoomMostUsedBy(state.roomMostUsedBy.getOrCrash()), - roomPermissions: RoomPermissions(state.roomPermissions.getOrCrash()), - ); - - IRoomRepository.instance.create(roomEntity); - } - - Future _createRoom( - CreateRoom event, - Emitter emit, - ) async { - final RoomEntity roomEntity = RoomEntity( - uniqueId: RoomUniqueId.fromUniqueString(state.roomUniqueId.getOrCrash()), - cbjEntityName: RoomDefaultName(state.cbjEntityName.getOrCrash()), - background: RoomBackground(state.background.getOrCrash()), - roomTypes: RoomTypes(state.roomTypes.getOrCrash()), - roomDevicesId: RoomDevicesId(state.roomDevicesId.getOrCrash()), - roomScenesId: RoomScenesId(state.roomScenesId.getOrCrash()), - roomRoutinesId: RoomRoutinesId(state.roomRoutinesId.getOrCrash()), - roomBindingsId: RoomBindingsId(state.roomBindingsId.getOrCrash()), - roomMostUsedBy: RoomMostUsedBy(state.roomMostUsedBy.getOrCrash()), - roomPermissions: RoomPermissions(state.roomPermissions.getOrCrash()), - ); - - IRoomRepository.instance.create(roomEntity); - } - - Future _defaultNameChanged( - DefaultNameChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - cbjEntityName: RoomDefaultName(event.cbjEntityName), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _roomTypesChanged( - RoomTypesChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - roomTypes: RoomTypes(event.roomTypes), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _roomIdChanged( - RoomIdChanged event, - Emitter emit, - ) async { - for (final RoomEntity? roomEntity in _allRooms) { - if (roomEntity != null && - roomEntity.uniqueId.getOrCrash() == event.roomId) { - emit( - state.copyWith( - roomUniqueId: roomEntity.uniqueId, - cbjEntityName: roomEntity.cbjEntityName, - authFailureOrSuccessOption: none(), - ), - ); - return; - } - } - } - - Future _roomDevicesIdChanged( - RoomDevicesIdChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - roomDevicesId: RoomDevicesId(event.roomDevicesId), - authFailureOrSuccessOption: none(), - ), - ); - // Navigator.pop(context); - } - - Future _roomMostUsedByChanged( - RoomMostUsedByChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - roomMostUsedBy: RoomMostUsedBy(event.roomMostUsedBy), - authFailureOrSuccessOption: none(), - ), - ); - } - - Future _roomPermissionsChanged( - RoomPermissionsChanged event, - Emitter emit, - ) async { - emit( - state.copyWith( - roomPermissions: RoomPermissions(event.roomPermissions), - authFailureOrSuccessOption: none(), - ), - ); - } -} diff --git a/lib/application/room/create_new_room_form/room_sign_in_form_event.dart b/lib/application/room/create_new_room_form/room_sign_in_form_event.dart deleted file mode 100644 index 60eb102a1..000000000 --- a/lib/application/room/create_new_room_form/room_sign_in_form_event.dart +++ /dev/null @@ -1,34 +0,0 @@ -part of 'room_sign_in_form_bloc.dart'; - -@freezed -class RoomSignInFormEvent with _$RoomSignInFormEvent { - const factory RoomSignInFormEvent.defaultNameChanged(String cbjEntityName) = - DefaultNameChanged; - - const factory RoomSignInFormEvent.roomTypesChanged( - List roomTypes, - ) = RoomTypesChanged; - - const factory RoomSignInFormEvent.roomIdChanged( - String roomId, - ) = RoomIdChanged; - - const factory RoomSignInFormEvent.roomDevicesIdChanged( - List roomDevicesId, - ) = RoomDevicesIdChanged; - - const factory RoomSignInFormEvent.roomMostUsedByChanged( - List roomMostUsedBy, - ) = RoomMostUsedByChanged; - - const factory RoomSignInFormEvent.roomPermissionsChanged( - List roomPermissions, - ) = RoomPermissionsChanged; - - const factory RoomSignInFormEvent.changeRoomDevices(BuildContext context) = - ChangeRoomDevices; - - const factory RoomSignInFormEvent.createRoom() = CreateRoom; - - const factory RoomSignInFormEvent.initialized() = Initialized; -} diff --git a/lib/application/room/create_new_room_form/room_sign_in_form_state.dart b/lib/application/room/create_new_room_form/room_sign_in_form_state.dart deleted file mode 100644 index 08bdcc536..000000000 --- a/lib/application/room/create_new_room_form/room_sign_in_form_state.dart +++ /dev/null @@ -1,42 +0,0 @@ -part of 'room_sign_in_form_bloc.dart'; - -@freezed -class RoomSignInFormState with _$RoomSignInFormState { - const factory RoomSignInFormState({ - required List allRooms, - required List allDevices, - required RoomUniqueId roomUniqueId, - required RoomDefaultName cbjEntityName, - required RoomBackground background, - required RoomTypes roomTypes, - required RoomDevicesId roomDevicesId, - required RoomScenesId roomScenesId, - required RoomRoutinesId roomRoutinesId, - required RoomBindingsId roomBindingsId, - required RoomMostUsedBy roomMostUsedBy, - required RoomPermissions roomPermissions, - required bool showErrorMessages, - required bool isSubmitting, - required Option> authFailureOrSuccessOption, - }) = _RoomSignInFormState; - - factory RoomSignInFormState.initial() => RoomSignInFormState( - allRooms: [], - allDevices: [], - roomUniqueId: RoomUniqueId(), - cbjEntityName: RoomDefaultName(''), - background: RoomBackground( - 'https://live.staticflickr.com/5220/5486044345_f67abff3e9_h.jpg', - ), - roomTypes: RoomTypes(const []), - roomDevicesId: RoomDevicesId(const []), - roomScenesId: RoomScenesId(const []), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - showErrorMessages: false, - isSubmitting: false, - authFailureOrSuccessOption: none(), - ); -} diff --git a/lib/application/scene/scene_bloc.dart b/lib/application/scene/scene_bloc.dart deleted file mode 100644 index 59f144e0d..000000000 --- a/lib/application/scene/scene_bloc.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; -import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'scene_bloc.freezed.dart'; -part 'scene_event.dart'; -part 'scene_state.dart'; - -@injectable -class SceneBloc extends Bloc { - SceneBloc() : super(SceneState.initialized()) { - on(_initialized); - on(_activateScene); - } - - late SceneCbjEntity sceneCbj; - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - emit(const SceneState.loading()); - sceneCbj = event.sceneCbj; - emit(SceneState.loaded(sceneCbj)); - } - - Future _activateScene( - ActivateScene event, - Emitter emit, - ) async { - ISceneCbjRepository.instance.activateScenes([sceneCbj].toImmutableList()); - } -} diff --git a/lib/application/scene/scene_event.dart b/lib/application/scene/scene_event.dart deleted file mode 100644 index d39c48ca8..000000000 --- a/lib/application/scene/scene_event.dart +++ /dev/null @@ -1,12 +0,0 @@ -part of 'scene_bloc.dart'; - -@freezed -class SceneEvent with _$SceneEvent { - const factory SceneEvent.initialized({required SceneCbjEntity sceneCbj}) = - Initialized; - - const factory SceneEvent.activateScene() = ActivateScene; -} - -// {required Either scene}) = Initialized; -// .fold((l) => null, (r) => r) diff --git a/lib/application/scene/scene_state.dart b/lib/application/scene/scene_state.dart deleted file mode 100644 index 1e56672b8..000000000 --- a/lib/application/scene/scene_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'scene_bloc.dart'; - -@freezed -class SceneState with _$SceneState { - const factory SceneState() = _SceneState; - - factory SceneState.initialized() => const SceneState(); - - const factory SceneState.loading() = _Loading; - - const factory SceneState.loaded(SceneCbjEntity sceneCbj) = _Loaded; - - const factory SceneState.error() = Error; -} diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart deleted file mode 100644 index 56904b660..000000000 --- a/lib/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_security_camera_device/generic_security_camera_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:url_launcher/url_launcher.dart'; - -part 'security_camera_actor_bloc.freezed.dart'; -part 'security_camera_actor_event.dart'; -part 'security_camera_actor_state.dart'; - -@injectable -class SecurityCamerasActorBloc - extends Bloc { - SecurityCamerasActorBloc() - : super(const SecurityCamerasActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllSecurityCameras); - on(_turnOnAllSecurityCameras); - on(_openSecurityCamerasWebPage); - on(_shutdownAllSecurityCameras); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllSecurityCameras( - TurnOffAllSecurityCameras event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.turnOffDevices( - devicesId: event.securityCamerasIdToTurnOff, - ); - } - - Future _turnOnAllSecurityCameras( - TurnOnAllSecurityCameras event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.securityCamerasIdToTurnOn); - } - - Future _openSecurityCamerasWebPage( - OpenSecurityCamerasWebPage event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Opening securityCameras Web Page', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - final String securityCameraIp = - event.securityCamera.deviceLastKnownIp.getOrCrash(); - launchUrl( - Uri.parse('http://$securityCameraIp'), - mode: LaunchMode.externalApplication, - ); - } - - Future _shutdownAllSecurityCameras( - ShutdownAllSecurityCameras event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Suspending all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .shutdownDevices(devicesId: event.securityCamerasId); - } -} diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart deleted file mode 100644 index 5716a12b1..000000000 --- a/lib/application/security_camera/security_camera_actor/security_camera_actor_event.dart +++ /dev/null @@ -1,30 +0,0 @@ -part of 'security_camera_actor_bloc.dart'; - -@freezed -class SecurityCamerasActorEvent with _$SecurityCamerasActorEvent { - const factory SecurityCamerasActorEvent.initialized() = Initialized; - - const factory SecurityCamerasActorEvent.turnOffAllSecurityCameras( - List securityCamerasIdToTurnOff, - BuildContext context, - ) = TurnOffAllSecurityCameras; - - const factory SecurityCamerasActorEvent.turnOnAllSecurityCameras( - List securityCamerasIdToTurnOn, - BuildContext context, - ) = TurnOnAllSecurityCameras; - - const factory SecurityCamerasActorEvent.openSecurityCamerasWebPage( - GenericSecurityCameraDE securityCamera, - BuildContext context, - ) = OpenSecurityCamerasWebPage; - - const factory SecurityCamerasActorEvent.shutdownAllSecurityCameras( - List securityCamerasId, - BuildContext context, - ) = ShutdownAllSecurityCameras; - - const factory SecurityCamerasActorEvent.deleted( - GenericSwitchDE deviceEntity, - ) = Deleted; -} diff --git a/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart b/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart deleted file mode 100644 index 0e4cea548..000000000 --- a/lib/application/security_camera/security_camera_actor/security_camera_actor_state.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'security_camera_actor_bloc.dart'; - -@freezed -class SecurityCamerasActorState with _$SecurityCamerasActorState { - const factory SecurityCamerasActorState.initial() = _Initial; - - const factory SecurityCamerasActorState.actionInProgress() = - _ActionInProgress; - - const factory SecurityCamerasActorState.deleteFailure( - DevicesFailure devicesFailure, - ) = _DeleteFailure; - - const factory SecurityCamerasActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart deleted file mode 100644 index dbd0249c8..000000000 --- a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_bloc.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'security_camera_watcher_bloc.freezed.dart'; -part 'security_camera_watcher_event.dart'; -part 'security_camera_watcher_state.dart'; - -@injectable -class SecurityCamerasWatcherBloc - extends Bloc { - SecurityCamerasWatcherBloc() : super(SecurityCamerasWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const SecurityCamerasWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - // _deviceStreamSubscription = - // IDeviceRepository.instance.watchSecurityCameras().listen( - // (eventWatch) => - // add(SecurityCamerasWatcherEvent.devicesReceived(eventWatch)), - // ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const SecurityCamerasWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => SecurityCamerasWatcherState.loadFailure(f), - (d) => SecurityCamerasWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart deleted file mode 100644 index 47ea38a46..000000000 --- a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'security_camera_watcher_bloc.dart'; - -@freezed -class SecurityCamerasWatcherEvent with _$SecurityCamerasWatcherEvent { - const factory SecurityCamerasWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory SecurityCamerasWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart b/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart deleted file mode 100644 index 68b1c7b00..000000000 --- a/lib/application/security_camera/security_camera_watcher/security_camera_watcher_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'security_camera_watcher_bloc.dart'; - -@freezed -class SecurityCamerasWatcherState with _$SecurityCamerasWatcherState { - factory SecurityCamerasWatcherState.initial() = _Initial; - - const factory SecurityCamerasWatcherState.loadInProgress() = _LoadInProgress; - - const factory SecurityCamerasWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory SecurityCamerasWatcherState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory SecurityCamerasWatcherState.securityCamerasError() = - SecurityCamerasError; -} diff --git a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart deleted file mode 100644 index 50847a797..000000000 --- a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart +++ /dev/null @@ -1,90 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'smart_computers_actor_bloc.freezed.dart'; -part 'smart_computers_actor_event.dart'; -part 'smart_computers_actor_state.dart'; - -@injectable -class SmartComputersActorBloc - extends Bloc { - SmartComputersActorBloc() : super(const SmartComputersActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllSmartComputers); - on(_turnOnAllSmartComputers); - on(_suspendAllSmartComputers); - on(_shutdownAllSmartComputers); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllSmartComputers( - TurnOffAllSmartComputers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.turnOffDevices( - devicesId: event.smartComputersIdToTurnOff, - ); - } - - Future _turnOnAllSmartComputers( - TurnOnAllSmartComputers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.smartComputersIdToTurnOn); - } - - Future _suspendAllSmartComputers( - SuspendAllSmartComputers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Suspending all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .suspendDevices(devicesId: event.smartComputersId); - } - - Future _shutdownAllSmartComputers( - ShutdownAllSmartComputers event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Suspending all Smart Computers', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .shutdownDevices(devicesId: event.smartComputersId); - } -} diff --git a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_event.dart b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_event.dart deleted file mode 100644 index 3862a73e9..000000000 --- a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_event.dart +++ /dev/null @@ -1,29 +0,0 @@ -part of 'smart_computers_actor_bloc.dart'; - -@freezed -class SmartComputersActorEvent with _$SmartComputersActorEvent { - const factory SmartComputersActorEvent.initialized() = Initialized; - - const factory SmartComputersActorEvent.turnOffAllSmartComputers( - List smartComputersIdToTurnOff, - BuildContext context, - ) = TurnOffAllSmartComputers; - - const factory SmartComputersActorEvent.turnOnAllSmartComputers( - List smartComputersIdToTurnOn, - BuildContext context, - ) = TurnOnAllSmartComputers; - - const factory SmartComputersActorEvent.suspendAllSmartComputers( - List smartComputersId, - BuildContext context, - ) = SuspendAllSmartComputers; - - const factory SmartComputersActorEvent.shutdownAllSmartComputers( - List smartComputersId, - BuildContext context, - ) = ShutdownAllSmartComputers; - - const factory SmartComputersActorEvent.deleted(GenericSwitchDE deviceEntity) = - Deleted; -} diff --git a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_state.dart b/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_state.dart deleted file mode 100644 index 7aab4da48..000000000 --- a/lib/application/smart_computers/smart_computers_actor/smart_computers_actor_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'smart_computers_actor_bloc.dart'; - -@freezed -class SmartComputersActorState with _$SmartComputersActorState { - const factory SmartComputersActorState.initial() = _Initial; - - const factory SmartComputersActorState.actionInProgress() = _ActionInProgress; - - const factory SmartComputersActorState.deleteFailure( - DevicesFailure devicesFailure, - ) = _DeleteFailure; - - const factory SmartComputersActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart deleted file mode 100644 index 14774d861..000000000 --- a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'smart_computer_watcher_bloc.freezed.dart'; -part 'smart_computer_watcher_event.dart'; -part 'smart_computer_watcher_state.dart'; - -@injectable -class SmartComputersWatcherBloc - extends Bloc { - SmartComputersWatcherBloc() : super(SmartComputersWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const SmartComputersWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = - IDeviceRepository.instance.watchSmartComputers().listen( - (eventWatch) => - add(SmartComputersWatcherEvent.devicesReceived(eventWatch)), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const SmartComputersWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => SmartComputersWatcherState.loadFailure(f), - (d) => SmartComputersWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_event.dart b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_event.dart deleted file mode 100644 index 4431a9d33..000000000 --- a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'smart_computer_watcher_bloc.dart'; - -@freezed -class SmartComputersWatcherEvent with _$SmartComputersWatcherEvent { - const factory SmartComputersWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory SmartComputersWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_state.dart b/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_state.dart deleted file mode 100644 index 8649a9963..000000000 --- a/lib/application/smart_computers/smart_computers_watcher/smart_computer_watcher_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'smart_computer_watcher_bloc.dart'; - -@freezed -class SmartComputersWatcherState with _$SmartComputersWatcherState { - factory SmartComputersWatcherState.initial() = _Initial; - - const factory SmartComputersWatcherState.loadInProgress() = _LoadInProgress; - - const factory SmartComputersWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory SmartComputersWatcherState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory SmartComputersWatcherState.smartComputersError() = - SmartComputersError; -} diff --git a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart b/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart deleted file mode 100644 index 3b58193e6..000000000 --- a/lib/application/smart_plug_toggle/smart_plug_toggle_bloc.dart +++ /dev/null @@ -1,84 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/widgets.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'smart_plug_toggle_bloc.freezed.dart'; -part 'smart_plug_toggle_event.dart'; -part 'smart_plug_toggle_state.dart'; - -@injectable -class SmartPlugToggleBloc - extends Bloc { - SmartPlugToggleBloc() : super(SmartPlugToggleState.initial()) { - on(_create); - on(_changeAction); - on(_changeColor); - } - - int sendNewColorEachMiliseconds = 200; - Timer? timeFromLastColorChange; - HSVColor? lastColoredPicked; - - Future _create( - CreateDevice event, - Emitter emit, - ) async { - await IDeviceRepository.instance.create(event.deviceEntity); - } - - Future _changeAction( - ChangeState event, - Emitter emit, - ) async { - const SmartPlugToggleState.loadInProgress(); - - Either actionResult; - - if (event.changeToState) { - actionResult = await IDeviceRepository.instance.turnOnDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } else { - actionResult = await IDeviceRepository.instance.turnOffDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } - - emit( - actionResult.fold( - (devicesFailure) => SmartPlugToggleState.loadFailure(devicesFailure), - (_) => const SmartPlugToggleState.loadSuccess(), - ), - ); - } - - Future _changeColor( - ChangeColor event, - Emitter emit, - ) async { - lastColoredPicked = event.newColor; - timeFromLastColorChange ??= - Timer(Duration(milliseconds: sendNewColorEachMiliseconds), () { - timeFromLastColorChange = null; - changeColorOncePerTimer(event); - }); - } - - /// This function will make sure that the app sends color once each x seconds. - /// Moving the hand on the color slider sends tons of requests with - /// different colors which is not efficient and some device can't even handle - /// so many requests. - Future changeColorOncePerTimer(ChangeColor e) async { - await IDeviceRepository.instance.changeHsvColorDevices( - devicesId: [e.deviceEntity.uniqueId.getOrCrash()], - hsvColorToChange: lastColoredPicked!, - ); - } -} diff --git a/lib/application/smart_plug_toggle/smart_plug_toggle_event.dart b/lib/application/smart_plug_toggle/smart_plug_toggle_event.dart deleted file mode 100644 index a6a67176c..000000000 --- a/lib/application/smart_plug_toggle/smart_plug_toggle_event.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'smart_plug_toggle_bloc.dart'; - -@freezed -class SmartPlugToggleEvent with _$SmartPlugToggleEvent { - const factory SmartPlugToggleEvent.changeAction( - DeviceEntityAbstract deviceEntity, - bool changeToState, - ) = ChangeState; - - const factory SmartPlugToggleEvent.changeColor( - DeviceEntityAbstract deviceEntity, - HSVColor newColor, - ) = ChangeColor; - - const factory SmartPlugToggleEvent.create(DeviceEntityAbstract deviceEntity) = - CreateDevice; -} diff --git a/lib/application/smart_plug_toggle/smart_plug_toggle_state.dart b/lib/application/smart_plug_toggle/smart_plug_toggle_state.dart deleted file mode 100644 index 8098ce070..000000000 --- a/lib/application/smart_plug_toggle/smart_plug_toggle_state.dart +++ /dev/null @@ -1,16 +0,0 @@ -part of 'smart_plug_toggle_bloc.dart'; - -@freezed -class SmartPlugToggleState with _$SmartPlugToggleState { - factory SmartPlugToggleState.initial() = _Initial; - - const factory SmartPlugToggleState.loadInProgress() = _LoadInProgress; - - const factory SmartPlugToggleState.loadSuccess() = _LoadSuccess; - - const factory SmartPlugToggleState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory SmartPlugToggleState.error() = Error; -} diff --git a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart deleted file mode 100644 index 2c2438011..000000000 --- a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'smart_plugs_actor_bloc.freezed.dart'; -part 'smart_plugs_actor_event.dart'; -part 'smart_plugs_actor_state.dart'; - -@injectable -class SmartPlugsActorBloc - extends Bloc { - SmartPlugsActorBloc() : super(const SmartPlugsActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllSmartPlugs); - on(_turnOnAllSmartPlugs); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllSmartPlugs( - TurnOffAllSmartPlugs event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all smartPlugs', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOffDevices(devicesId: event.smartPlugsIdToTurnOff); - } - - Future _turnOnAllSmartPlugs( - TurnOnAllSmartPlugs event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all smartPlugs', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.smartPlugsIdToTurnOn); - } -} diff --git a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_event.dart b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_event.dart deleted file mode 100644 index dfca4af15..000000000 --- a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_event.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'smart_plugs_actor_bloc.dart'; - -@freezed -class SmartPlugsActorEvent with _$SmartPlugsActorEvent { - const factory SmartPlugsActorEvent.initialized() = Initialized; - - const factory SmartPlugsActorEvent.turnOffAllSmartPlugs( - List smartPlugsIdToTurnOff, - BuildContext context, - ) = TurnOffAllSmartPlugs; - - const factory SmartPlugsActorEvent.turnOnAllSmartPlugs( - List smartPlugsIdToTurnOn, - BuildContext context, - ) = TurnOnAllSmartPlugs; - - const factory SmartPlugsActorEvent.deleted(GenericSmartPlugDE deviceEntity) = - Deleted; -} diff --git a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_state.dart b/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_state.dart deleted file mode 100644 index 3650016d4..000000000 --- a/lib/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'smart_plugs_actor_bloc.dart'; - -@freezed -class SmartPlugsActorState with _$SmartPlugsActorState { - const factory SmartPlugsActorState.initial() = _Initial; - - const factory SmartPlugsActorState.actionInProgress() = _ActionInProgress; - - const factory SmartPlugsActorState.deleteFailure( - DevicesFailure devicesFailure, - ) = _DeleteFailure; - - const factory SmartPlugsActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart deleted file mode 100644 index 5fa0b219e..000000000 --- a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'smart_plugs_watcher_bloc.freezed.dart'; -part 'smart_plugs_watcher_event.dart'; -part 'smart_plugs_watcher_state.dart'; - -@injectable -class SmartPlugsWatcherBloc - extends Bloc { - SmartPlugsWatcherBloc() : super(SmartPlugsWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const SmartPlugsWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = - IDeviceRepository.instance.watchSmartPlugs().listen( - (eventWatch) => - add(SmartPlugsWatcherEvent.devicesReceived(eventWatch)), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const SmartPlugsWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => SmartPlugsWatcherState.loadFailure(f), - (d) => SmartPlugsWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_event.dart b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_event.dart deleted file mode 100644 index f5bddbfc3..000000000 --- a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'smart_plugs_watcher_bloc.dart'; - -@freezed -class SmartPlugsWatcherEvent with _$SmartPlugsWatcherEvent { - const factory SmartPlugsWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory SmartPlugsWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_state.dart b/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_state.dart deleted file mode 100644 index 69d6f4651..000000000 --- a/lib/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'smart_plugs_watcher_bloc.dart'; - -@freezed -class SmartPlugsWatcherState with _$SmartPlugsWatcherState { - factory SmartPlugsWatcherState.initial() = _Initial; - - const factory SmartPlugsWatcherState.loadInProgress() = _LoadInProgress; - - const factory SmartPlugsWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory SmartPlugsWatcherState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory SmartPlugsWatcherState.smartPlugsError() = SmartPlugsError; -} diff --git a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart b/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart deleted file mode 100644 index e9bf00035..000000000 --- a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart +++ /dev/null @@ -1,145 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'smart_tv_actor_bloc.freezed.dart'; -part 'smart_tv_actor_event.dart'; -part 'smart_tv_actor_state.dart'; - -@injectable -class SmartTvActorBloc extends Bloc { - SmartTvActorBloc() - : super(const SmartTvActorState.initial()) { - on(_initialized); - on(_openUrl); - on(_stopState); - on(_closeEvent); - on(_pauseState); - on(_playState); - on(_skipVideoTo); - on(_changeVolume); - on(_queuePrevEvent); - on(_queueNextEvent); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _openUrl( - OpenUrl event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Open url on smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - IDeviceRepository.instance.openUrlOnDevices( - devicesId: event.smartTvId, - url: event.url, - ); - } - - Future _stopState( - StopEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Stop smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.stopStateDevices(devicesId: event.smartTvId); - } - - Future _closeEvent( - CloseEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Close current app on smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.closeStateDevices(devicesId: event.smartTvId); - } - - Future _pauseState( - PauseEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Pause smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.pauseStateDevices(devicesId: event.smartTvId); - } - - Future _playState( - PlayEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Play smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.playStateDevices(devicesId: event.smartTvId); - } - - Future _skipVideoTo( - SkipVideoTo event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Skip smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.skipVideoDevices(devicesId: event.smartTvId); - } - - Future _changeVolume( - ChangeVolume event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Change volume smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.changeVolumeDevices(devicesId: event.smartTvId); - } - - Future _queuePrevEvent( - QueuePrevEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Change volume smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.queuePrevStateDevices(devicesId: event.smartTvId); - } - - Future _queueNextEvent( - QueueNextEvent event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Change volume smart tv', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance.queueNextStateDevices(devicesId: event.smartTvId); - } -} diff --git a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_event.dart b/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_event.dart deleted file mode 100644 index d361af22b..000000000 --- a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_event.dart +++ /dev/null @@ -1,52 +0,0 @@ -part of 'smart_tv_actor_bloc.dart'; - -@freezed -class SmartTvActorEvent with _$SmartTvActorEvent { - const factory SmartTvActorEvent.initialized() = Initialized; - - const factory SmartTvActorEvent.openUrl( - BuildContext context, - List? smartTvId, - String url, - ) = OpenUrl; - - const factory SmartTvActorEvent.stopEvent( - List? smartTvId, - BuildContext context, - ) = StopEvent; - - const factory SmartTvActorEvent.pauseEvent( - List? smartTvId, - BuildContext context, - ) = PauseEvent; - - const factory SmartTvActorEvent.closeEvent( - List? smartTvId, - BuildContext context, - ) = CloseEvent; - - const factory SmartTvActorEvent.playEvent( - List? smartTvId, - BuildContext context, - ) = PlayEvent; - - const factory SmartTvActorEvent.skipVideoTo( - List? smartTvId, - BuildContext context, - ) = SkipVideoTo; - - const factory SmartTvActorEvent.changeVolume( - List? smartTvId, - BuildContext context, - ) = ChangeVolume; - - const factory SmartTvActorEvent.queuePrevEvent( - List? smartTvId, - BuildContext context, - ) = QueuePrevEvent; - - const factory SmartTvActorEvent.queueNextEvent( - List? smartTvId, - BuildContext context, - ) = QueueNextEvent; -} diff --git a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_state.dart b/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_state.dart deleted file mode 100644 index 3ec13ee85..000000000 --- a/lib/application/smart_tv/smart_tv_actor/smart_tv_actor_state.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'smart_tv_actor_bloc.dart'; - -@freezed -class SmartTvActorState with _$SmartTvActorState { - const factory SmartTvActorState.initial() = _Initial; - - const factory SmartTvActorState.actionInProgress() = _ActionInProgress; - - const factory SmartTvActorState.deleteFailure(DevicesFailure devicesFailure) = - _DeleteFailure; - - const factory SmartTvActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart b/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart deleted file mode 100644 index dbabf0039..000000000 --- a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'smart_tv_watcher_bloc.freezed.dart'; -part 'smart_tv_watcher_event.dart'; -part 'smart_tv_watcher_state.dart'; - -@injectable -class SmartTvWatcherBloc - extends Bloc { - SmartTvWatcherBloc() - : super(SmartTvWatcherState.initial()) { - on(_watchAllStarted); - on(_smartTvReceived); - } - - Future _watchAllStarted( - WatchAllSmartTvStarted event, - Emitter emit, - ) async { - emit(const SmartTvWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = IDeviceRepository.instance.watchSmartTv().listen( - (eventWatch) => add(SmartTvWatcherEvent.smartTvReceived(eventWatch)), - ); - } - - Future _smartTvReceived( - Smart_tvReceived event, - Emitter emit, - ) async { - emit(const SmartTvWatcherState.loadInProgress()); - - emit( - event.failureOrDevices.fold( - (f) => SmartTvWatcherState.loadFailure(f), - (d) => SmartTvWatcherState.loadSuccess( - d.map((v) => v! as GenericSmartTvDE).toMutableList(), - ), - ), - ); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_event.dart b/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_event.dart deleted file mode 100644 index a8986a4ae..000000000 --- a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'smart_tv_watcher_bloc.dart'; - -@freezed -class SmartTvWatcherEvent with _$SmartTvWatcherEvent { - const factory SmartTvWatcherEvent.watchAllStarted() = WatchAllSmartTvStarted; - - const factory SmartTvWatcherEvent.smartTvReceived( - Either> failureOrDevices, - ) = Smart_tvReceived; -} diff --git a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_state.dart b/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_state.dart deleted file mode 100644 index 51062fda1..000000000 --- a/lib/application/smart_tv/smart_tv_watcher/smart_tv_watcher_state.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'smart_tv_watcher_bloc.dart'; - -@freezed -class SmartTvWatcherState with _$SmartTvWatcherState { - factory SmartTvWatcherState.initial() = Initial; - - const factory SmartTvWatcherState.loadInProgress() = LoadInProgress; - - const factory SmartTvWatcherState.loadSuccess( - KtList devices, - ) = LoadSuccess; - - const factory SmartTvWatcherState.loadFailure(DevicesFailure devicesFailure) = - LoadFailure; - - const factory SmartTvWatcherState.smartTvsError() = SmartTvsError; -} diff --git a/lib/application/switch_toggle/switch_toggle_bloc.dart b/lib/application/switch_toggle/switch_toggle_bloc.dart deleted file mode 100644 index 68b884ab2..000000000 --- a/lib/application/switch_toggle/switch_toggle_bloc.dart +++ /dev/null @@ -1,83 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:flutter/widgets.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'switch_toggle_bloc.freezed.dart'; -part 'switch_toggle_event.dart'; -part 'switch_toggle_state.dart'; - -@injectable -class SwitchToggleBloc extends Bloc { - SwitchToggleBloc() : super(SwitchToggleState.initial()) { - on(_create); - on(_changeAction); - on(_changeColor); - } - - int sendNewColorEachMiliseconds = 200; - Timer? timeFromLastColorChange; - HSVColor? lastColoredPicked; - - Future _create( - CreateDevice event, - Emitter emit, - ) async { - await IDeviceRepository.instance.create(event.deviceEntity); - } - - Future _changeAction( - ChangeState event, - Emitter emit, - ) async { - const SwitchToggleState.loadInProgress(); - - Either actionResult; - - if (event.changeToState) { - actionResult = await IDeviceRepository.instance.turnOnDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } else { - actionResult = await IDeviceRepository.instance.turnOffDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } - - emit( - actionResult.fold( - (devicesFailure) => SwitchToggleState.loadFailure(devicesFailure), - (_) => const SwitchToggleState.loadSuccess(), - ), - ); - } - - Future _changeColor( - ChangeColor event, - Emitter emit, - ) async { - lastColoredPicked = event.newColor; - timeFromLastColorChange ??= - Timer(Duration(milliseconds: sendNewColorEachMiliseconds), () { - timeFromLastColorChange = null; - changeColorOncePerTimer(event); - }); - } - - /// This function will make sure that the app sends color once each x seconds. - /// Moving the hand on the color slider sends tons of requests with - /// different colors which is not efficient and some device can't even handle - /// so many requests. - Future changeColorOncePerTimer(ChangeColor e) async { - await IDeviceRepository.instance.changeHsvColorDevices( - devicesId: [e.deviceEntity.uniqueId.getOrCrash()], - hsvColorToChange: lastColoredPicked!, - ); - } -} diff --git a/lib/application/switch_toggle/switch_toggle_event.dart b/lib/application/switch_toggle/switch_toggle_event.dart deleted file mode 100644 index cb9e25705..000000000 --- a/lib/application/switch_toggle/switch_toggle_event.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'switch_toggle_bloc.dart'; - -@freezed -class SwitchToggleEvent with _$SwitchToggleEvent { - const factory SwitchToggleEvent.changeAction( - DeviceEntityAbstract deviceEntity, - bool changeToState, - ) = ChangeState; - - const factory SwitchToggleEvent.changeColor( - DeviceEntityAbstract deviceEntity, - HSVColor newColor, - ) = ChangeColor; - - const factory SwitchToggleEvent.create(DeviceEntityAbstract deviceEntity) = - CreateDevice; -} diff --git a/lib/application/switch_toggle/switch_toggle_state.dart b/lib/application/switch_toggle/switch_toggle_state.dart deleted file mode 100644 index a398d91ee..000000000 --- a/lib/application/switch_toggle/switch_toggle_state.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'switch_toggle_bloc.dart'; - -@freezed -class SwitchToggleState with _$SwitchToggleState { - factory SwitchToggleState.initial() = _Initial; - - const factory SwitchToggleState.loadInProgress() = _LoadInProgress; - - const factory SwitchToggleState.loadSuccess() = _LoadSuccess; - - const factory SwitchToggleState.loadFailure(DevicesFailure devicesFailure) = - _loadFailure; - - const factory SwitchToggleState.error() = Error; -} diff --git a/lib/application/switches/switches_actor/switches_actor_bloc.dart b/lib/application/switches/switches_actor/switches_actor_bloc.dart deleted file mode 100644 index de8b440fe..000000000 --- a/lib/application/switches/switches_actor/switches_actor_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'switches_actor_bloc.freezed.dart'; -part 'switches_actor_event.dart'; -part 'switches_actor_state.dart'; - -@injectable -class SwitchesActorBloc extends Bloc { - SwitchesActorBloc() : super(const SwitchesActorState.initial()) { - on(_initialized); - on(_deleted); - on(_turnOffAllSwitches); - on(_turnOnAllSwitches); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _turnOffAllSwitches( - TurnOffAllSwitches event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning Off all switches', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOffDevices(devicesId: event.switchesIdToTurnOff); - } - - Future _turnOnAllSwitches( - TurnOnAllSwitches event, - Emitter emit, - ) async { - FlushbarHelper.createLoading( - message: 'Turning On all switches', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(event.context); - - IDeviceRepository.instance - .turnOnDevices(devicesId: event.switchesIdToTurnOn); - } -} diff --git a/lib/application/switches/switches_actor/switches_actor_event.dart b/lib/application/switches/switches_actor/switches_actor_event.dart deleted file mode 100644 index 9af38c63b..000000000 --- a/lib/application/switches/switches_actor/switches_actor_event.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'switches_actor_bloc.dart'; - -@freezed -class SwitchesActorEvent with _$SwitchesActorEvent { - const factory SwitchesActorEvent.initialized() = Initialized; - - const factory SwitchesActorEvent.turnOffAllSwitches( - List switchesIdToTurnOff, - BuildContext context, - ) = TurnOffAllSwitches; - - const factory SwitchesActorEvent.turnOnAllSwitches( - List switchesIdToTurnOn, - BuildContext context, - ) = TurnOnAllSwitches; - - const factory SwitchesActorEvent.deleted(GenericSwitchDE deviceEntity) = - Deleted; -} diff --git a/lib/application/switches/switches_actor/switches_actor_state.dart b/lib/application/switches/switches_actor/switches_actor_state.dart deleted file mode 100644 index 9ffc43805..000000000 --- a/lib/application/switches/switches_actor/switches_actor_state.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'switches_actor_bloc.dart'; - -@freezed -class SwitchesActorState with _$SwitchesActorState { - const factory SwitchesActorState.initial() = _Initial; - - const factory SwitchesActorState.actionInProgress() = _ActionInProgress; - - const factory SwitchesActorState.deleteFailure( - DevicesFailure devicesFailure, - ) = _DeleteFailure; - - const factory SwitchesActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart b/lib/application/switches/switches_watcher/switches_watcher_bloc.dart deleted file mode 100644 index da6299eae..000000000 --- a/lib/application/switches/switches_watcher/switches_watcher_bloc.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'switches_watcher_bloc.freezed.dart'; -part 'switches_watcher_event.dart'; -part 'switches_watcher_state.dart'; - -@injectable -class SwitchesWatcherBloc - extends Bloc { - SwitchesWatcherBloc() : super(SwitchesWatcherState.initial()) { - on(_watchAllStarted); - on(_devicesReceived); - } - - StreamSubscription>>? - _deviceStreamSubscription; - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const SwitchesWatcherState.loadInProgress()); - await _deviceStreamSubscription?.cancel(); - _deviceStreamSubscription = - IDeviceRepository.instance.watchSwitches().listen( - (eventWatch) => - add(SwitchesWatcherEvent.devicesReceived(eventWatch)), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const SwitchesWatcherState.loadInProgress()); - emit( - event.failureOrDevices.fold( - (f) => SwitchesWatcherState.loadFailure(f), - (d) => SwitchesWatcherState.loadSuccess( - d.map((v) => v!).toMutableList(), - ), - ), - ); - } - - @override - Future close() async { - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/switches/switches_watcher/switches_watcher_event.dart b/lib/application/switches/switches_watcher/switches_watcher_event.dart deleted file mode 100644 index 50c2902c0..000000000 --- a/lib/application/switches/switches_watcher/switches_watcher_event.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'switches_watcher_bloc.dart'; - -@freezed -class SwitchesWatcherEvent with _$SwitchesWatcherEvent { - const factory SwitchesWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory SwitchesWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/switches/switches_watcher/switches_watcher_state.dart b/lib/application/switches/switches_watcher/switches_watcher_state.dart deleted file mode 100644 index 9e30420e9..000000000 --- a/lib/application/switches/switches_watcher/switches_watcher_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'switches_watcher_bloc.dart'; - -@freezed -class SwitchesWatcherState with _$SwitchesWatcherState { - factory SwitchesWatcherState.initial() = _Initial; - - const factory SwitchesWatcherState.loadInProgress() = _LoadInProgress; - - const factory SwitchesWatcherState.loadSuccess( - KtList devices, - ) = _loadSuccess; - - const factory SwitchesWatcherState.loadFailure( - DevicesFailure devicesFailure, - ) = _loadFailure; - - const factory SwitchesWatcherState.switchesError() = SwitchesError; -} diff --git a/lib/infrastructure/devices/device/device_repository.dart b/lib/infrastructure/devices/device/device_repository.dart index 079adbcb4..a099f1aa2 100644 --- a/lib/infrastructure/devices/device/device_repository.dart +++ b/lib/infrastructure/devices/device/device_repository.dart @@ -478,7 +478,7 @@ class DeviceRepository implements IDeviceRepository { await Future.delayed( Duration( milliseconds: - deviceEntity.sendNewTemperatureColorEachMiliseconds, + deviceEntity.sendNewTemperatureColorEachMilliseconds, ), ); deviceEntity.doesWaitingToSendTemperatureColorRequest = false; @@ -488,7 +488,8 @@ class DeviceRepository implements IDeviceRepository { } catch (e) { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewTemperatureColorEachMiliseconds, + milliseconds: + deviceEntity.sendNewTemperatureColorEachMilliseconds, ), ); deviceEntity.doesWaitingToSendTemperatureColorRequest = false; @@ -550,7 +551,7 @@ class DeviceRepository implements IDeviceRepository { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewHsvColorEachMiliseconds, + milliseconds: deviceEntity.sendNewHsvColorEachMilliseconds, ), ); deviceEntity.doesWaitingToSendHsvColorRequest = false; @@ -560,7 +561,7 @@ class DeviceRepository implements IDeviceRepository { } catch (e) { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewHsvColorEachMiliseconds, + milliseconds: deviceEntity.sendNewHsvColorEachMilliseconds, ), ); deviceEntity.doesWaitingToSendHsvColorRequest = false; @@ -640,7 +641,7 @@ class DeviceRepository implements IDeviceRepository { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewBrightnessEachMiliseconds, + milliseconds: deviceEntity.sendNewBrightnessEachMilliseconds, ), ); deviceEntity.doesWaitingToSendBrightnessRequest = false; @@ -649,7 +650,7 @@ class DeviceRepository implements IDeviceRepository { } catch (e) { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewBrightnessEachMiliseconds, + milliseconds: deviceEntity.sendNewBrightnessEachMilliseconds, ), ); deviceEntity.doesWaitingToSendBrightnessRequest = false; @@ -670,7 +671,7 @@ class DeviceRepository implements IDeviceRepository { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewBrightnessEachMiliseconds, + milliseconds: deviceEntity.sendNewBrightnessEachMilliseconds, ), ); deviceEntity.doesWaitingToSendBrightnessRequest = false; @@ -679,7 +680,7 @@ class DeviceRepository implements IDeviceRepository { } catch (e) { await Future.delayed( Duration( - milliseconds: deviceEntity.sendNewBrightnessEachMiliseconds, + milliseconds: deviceEntity.sendNewBrightnessEachMilliseconds, ), ); deviceEntity.doesWaitingToSendBrightnessRequest = false; diff --git a/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart b/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart index ffe9e513c..52b3246ee 100644 --- a/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart +++ b/lib/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -40,12 +37,8 @@ class ComputerConnectionCheckPage extends StatelessWidget { leftIconFunction: leftIconFunction, ), Expanded( - child: BlocProvider( - create: (context) => getIt() - ..add(const ConfigureNewCbjCompEvent.initialized()), - child: - ComputerConnectionCheckWidget(cbjCompEntity: cbjCompEntity), - ), + child: + ComputerConnectionCheckWidget(cbjCompEntity: cbjCompEntity), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart index 186c50d23..3a079e404 100644 --- a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart @@ -1,14 +1,24 @@ import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; +import 'package:cbj_integrations_controller/utils.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; +import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; +import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; +import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:cybear_jinni/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:kt_dart/collection.dart'; import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart'; +import 'package:wifi_iot/wifi_iot.dart'; +import 'package:wifi_scan/wifi_scan.dart'; -class ComputerConnectionCheckWidget extends StatelessWidget { +class ComputerConnectionCheckWidget extends StatefulWidget { const ComputerConnectionCheckWidget({ required this.cbjCompEntity, }); @@ -18,127 +28,230 @@ class ComputerConnectionCheckWidget extends StatelessWidget { static String deviceNameFieldKey = 'deviceNameField'; static String devicesDefaultRoomNameField = ''; + @override + State createState() => + _ComputerConnectionCheckWidgetState(); +} + +class _ComputerConnectionCheckWidgetState + extends State { + /// Progress counter for setting new devices + double progressPercentage = 0.0; + + ComputerConnectionCheckState state = ComputerConnectionCheckState.initial; + + @override + void initState() { + super.initState(); + _checkConnectedToWiFiNetwork(); + } + + void _routeToHub() { + FlushbarHelper.createLoading( + message: 'Hub got connected Successfully to you Home WiFi', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + } + + Future _checkConnectedToWiFiNetwork() async { + if ((await WiFiScan.instance.canStartScan()) == CanStartScan.yes) { + await WiFiScan.instance.startScan(); + if ((await WiFiScan.instance.canGetScannedResults()) == + CanGetScannedResults.yes) { + await WiFiScan.instance.getScannedResults(); + } + } + + bool isConnectedToWifi = false; + logger.i('Waiting for user to get connected to WiFi'); + + while (true) { + isConnectedToWifi = await WiFiForIoTPlugin.isConnected(); + if (isConnectedToWifi) { + break; + } + await Future.delayed(const Duration(seconds: 10)); + } + + progressPercentage += 50; + setState(() { + state = ComputerConnectionCheckState.actionInProgress; + }); + _searchIfHubOnTheSameWifiNetwork(); + } + + Future _searchIfHubOnTheSameWifiNetwork() async { + int connectionTimeout = 0; + + while (true) { + connectionTimeout++; + (await ISecurityBearConnectionRepository.instance + .searchForSecurityBearInCurrentNetwork()) + .fold((l) {}, (r) { + _routeToHub(); + + return; + }); + if (connectionTimeout == 10) { + break; + } + await Future.delayed(const Duration(seconds: 30)); + } + setState(() { + state = ComputerConnectionCheckState.errorInProcess; + }); + } + + /// Organize all the data from the text fields to updated CBJCompEntity + CBJCompEntity newCBJCompEntity( + CBJCompEntity cbjCompEntity, + Map textEditingController, + ) { + final String deviceNameFieldKey = + ConfigureNewCbjCompWidgets.deviceNameFieldKey; + final List deviceEntityList = []; + + textEditingController['allInSameRoom']!.text; + + final ManageNetworkEntity manageWiFiEntity = + IManageNetworkRepository.manageWiFiEntity!; + manageWiFiEntity.name!.getOrCrash(); + + cbjCompEntity.cBJCompDevices!.getOrCrash().asList().forEach((deviceE) { + try { + final String deviceName = textEditingController[ + '$deviceNameFieldKey/${deviceE.uniqueId.getOrCrash()}']! + .text; + deviceEntityList.add( + deviceE..cbjEntityName = CbjEntityName(deviceName), + ); + } catch (e) { + logger.w("Can't add unsupported device"); + } + }); + final CBJCompEntity compUpdatedData = cbjCompEntity.copyWith( + cBJCompDevices: CBJCompDevices(deviceEntityList.toImmutableList()), + ); + + return compUpdatedData; + } + + Future initialNewDevice(CBJCompEntity compUpdatedData) async { + bool error = false; + + final dartz.Either updateAllDevices = + await ICBJCompRepository.instance.firstSetup(compUpdatedData); + + updateAllDevices.fold( + (l) { + error = true; + }, + (r) {}, + ); + return error; + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) { - context.read().add( - const ConfigureNewCbjCompEvent.checkConnectedToWiFiNetwork(), - ); - - return const Expanded( - child: Center( - child: SizedBox( - height: 80, - width: 250, - child: TextAtom( - 'Please reconnect back to you home WiFi', - style: TextStyle(fontSize: 20), - ), - ), + switch (state) { + case ComputerConnectionCheckState.initial: + return const Expanded( + child: Center( + child: SizedBox( + height: 80, + width: 250, + child: TextAtom( + 'Please reconnect back to you home WiFi', + style: TextStyle(fontSize: 20), ), - ); - }, - actionInProgress: (ActionInProgress actionInProgress) { - context.read().add( - const ConfigureNewCbjCompEvent - .searchIfHubOnTheSameWifiNetwork(), - ); - return Column( - children: [ - const SizedBox( - height: 30, - ), - Container( - height: 35, - width: MediaQuery.of(context).size.width - 20, - decoration: const BoxDecoration( - color: Colors.black38, - borderRadius: BorderRadius.all(Radius.circular(10)), - ), - alignment: Alignment.center, - child: TextAtom( - 'Connecting computer to WiFi', - style: TextStyle( - fontSize: 25, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - Expanded( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - height: 80, - width: 250, - child: LiquidLinearProgressIndicator( - value: actionInProgress.progressPercentage, - valueColor: - const AlwaysStoppedAnimation(Colors.pink), - backgroundColor: - Theme.of(context).textTheme.bodyLarge!.color, - borderColor: Colors.red.withOpacity(0.9), - borderWidth: 4.0, - center: const TextAtom( - 'Loading...', - style: TextStyle(color: Colors.black), - ), - borderRadius: 2, - ), - ), - const SizedBox( - height: 20, - ), - TextAtom( - 'Searching for CyBear Jinni Hub in your WiFi network', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - ), + ), + ), + ); + + case ComputerConnectionCheckState.actionInProgress: + return Column( + children: [ + const SizedBox( + height: 30, + ), + Container( + height: 35, + width: MediaQuery.of(context).size.width - 20, + decoration: const BoxDecoration( + color: Colors.black38, + borderRadius: BorderRadius.all(Radius.circular(10)), + ), + alignment: Alignment.center, + child: TextAtom( + 'Connecting computer to WiFi', + style: TextStyle( + fontSize: 25, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ], - ); - }, - completeSuccess: (CompleteSuccess value) { - context.router.replace(const ConnectToHubRoute()); - - FlushbarHelper.createLoading( - message: 'Hub got connected Successfully to you Home WiFi', - linearProgressIndicator: const LinearProgressIndicator(), - ).show(context); - - return const TextAtom('completeSuccess'); - }, - errorInProcess: (ErrorInProcess value) { - return Expanded( + ), + ), + Expanded( child: Center( child: Column( + mainAxisAlignment: MainAxisAlignment.center, children: [ - const TextAtom( - 'Error finding CyBear Jinni Hub in your current' - ' network.\n' - 'Please restart connecting Hub to WiFi process.', + SizedBox( + height: 80, + width: 250, + child: LiquidLinearProgressIndicator( + value: progressPercentage, + valueColor: const AlwaysStoppedAnimation(Colors.pink), + backgroundColor: + Theme.of(context).textTheme.bodyLarge!.color, + borderColor: Colors.red.withOpacity(0.9), + borderWidth: 4.0, + center: const TextAtom( + 'Loading...', + style: TextStyle(color: Colors.black), + ), + borderRadius: 2, + ), ), - TextButton( - onPressed: () { - context.router.replace(const ConnectToHubRoute()); - }, - child: const TextAtom('Go Back'), + const SizedBox( + height: 20, + ), + TextAtom( + 'Searching for CyBear Jinni Hub in your WiFi network', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), ), ], ), ), - ); - }, + ), + ], ); - }, - ); + case ComputerConnectionCheckState.errorInProcess: + return Expanded( + child: Center( + child: Column( + children: [ + const TextAtom( + 'Error finding CyBear Jinni Hub in your current' + ' network.\n' + 'Please restart connecting Hub to WiFi process.', + ), + TextButton( + onPressed: _routeToHub, + child: const TextAtom('Go Back'), + ), + ], + ), + ), + ); + } } } + +enum ComputerConnectionCheckState { + initial, + actionInProgress, + errorInProcess, + ; +} diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart index 018eb1d78..b8c02c837 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/configure_new_cbj_comp_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -40,11 +37,7 @@ class ConfigureNewCbjCompPage extends StatelessWidget { leftIconFunction: leftIconFunction, ), Expanded( - child: BlocProvider( - create: (context) => getIt() - ..add(const ConfigureNewCbjCompEvent.initialized()), - child: ConfigureNewCbjCompWidgets(cbjCompEntity: cbjCompEntity), - ), + child: ConfigureNewCbjCompWidgets(cbjCompEntity: cbjCompEntity), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index 84925c4a7..5ef81f477 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -1,20 +1,31 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/application/configure_new_cbj_comp/configure_new_cbj_comp_bloc.dart'; +import 'package:cbj_integrations_controller/utils.dart'; import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; +import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; +import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; +import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.dart'; +import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; +import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; +import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/blinds_card.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/light_card.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:kt_dart/collection.dart'; import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart'; +import 'package:wifi_iot/wifi_iot.dart'; -class ConfigureNewCbjCompWidgets extends StatelessWidget { +class ConfigureNewCbjCompWidgets extends StatefulWidget { const ConfigureNewCbjCompWidgets({ required this.cbjCompEntity, }); @@ -24,6 +35,115 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { static String deviceNameFieldKey = 'deviceNameField'; static String devicesDefaultRoomNameField = ''; + @override + State createState() => + _ConfigureNewCbjCompWidgetsState(); +} + +class _ConfigureNewCbjCompWidgetsState + extends State { + ConfigureNewCbjCompState state = ConfigureNewCbjCompState.actionInProgress; + + /// Progress counter for setting new devices + double progressPercentage = 0.0; + + @override + void initState() { + super.initState(); + + _sendHotSpotInformation(widget.cbjCompEntity); + } + + Future _sendHotSpotInformation(CBJCompEntity cBJCompEntity) async { + progressPercentage += 0.3; + setState(() { + state = ConfigureNewCbjCompState.actionInProgress; + }); + + final CBJCompEntity compUpdatedData = cBJCompEntity; + final dartz.Either setSecurityBearWiFi = + await ISecurityBearConnectionRepository.instance + .setSecurityBearWiFiInformation(compUpdatedData); + + setSecurityBearWiFi.fold( + (l) { + setState(() { + state = ConfigureNewCbjCompState.errorInProcess; + }); + return; + }, + (r) { + progressPercentage += 0.5; + WiFiForIoTPlugin.disconnect(); + + setState(() { + state = ConfigureNewCbjCompState.actionInProgress; + }); + }, + ); + } + + void routeToHub() { + context.router.replace( + ComputerConnectionCheckRoute( + cbjCompEntity: widget.cbjCompEntity, + ), + ); + + setState(() { + state = ConfigureNewCbjCompState.completeSuccess; + }); + } + + /// Organize all the data from the text fields to updated CBJCompEntity + CBJCompEntity newCBJCompEntity( + CBJCompEntity cbjCompEntity, + Map textEditingController, + ) { + final String deviceNameFieldKey = + ConfigureNewCbjCompWidgets.deviceNameFieldKey; + final List deviceEntityList = []; + + textEditingController['allInSameRoom']!.text; + + final ManageNetworkEntity manageWiFiEntity = + IManageNetworkRepository.manageWiFiEntity!; + manageWiFiEntity.name!.getOrCrash(); + + cbjCompEntity.cBJCompDevices!.getOrCrash().asList().forEach((deviceE) { + try { + final String deviceName = textEditingController[ + '$deviceNameFieldKey/${deviceE.uniqueId.getOrCrash()}']! + .text; + deviceEntityList.add( + deviceE..cbjEntityName = CbjEntityName(deviceName), + ); + } catch (e) { + logger.w("Can't add unsupported device"); + } + }); + final CBJCompEntity compUpdatedData = cbjCompEntity.copyWith( + cBJCompDevices: CBJCompDevices(deviceEntityList.toImmutableList()), + ); + + return compUpdatedData; + } + + Future initialNewDevice(CBJCompEntity compUpdatedData) async { + bool error = false; + + final dartz.Either updateAllDevices = + await ICBJCompRepository.instance.firstSetup(compUpdatedData); + + updateAllDevices.fold( + (l) { + error = true; + }, + (r) {}, + ); + return error; + } + Widget devicesList( CBJCompEntity cbjCompEntityForDeviceList, Map textEditingController, @@ -42,7 +162,7 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { text: device.cbjEntityName.value.getOrElse(() => ''), ); textEditingController[ - '$deviceNameFieldKey/${device.uniqueId.value.getOrElse(() => 'deviceId')}'] = + '${ConfigureNewCbjCompWidgets.deviceNameFieldKey}/${device.uniqueId.value.getOrElse(() => 'deviceId')}'] = textEditingControllerTemp; widgetList.add( Container( @@ -168,119 +288,97 @@ class ConfigureNewCbjCompWidgets extends StatelessWidget { @override Widget build(BuildContext context) { - final CBJCompEntity cbjCompEntityInBuild = cbjCompEntity; final Map textEditingController = {}; textEditingController['allInSameRoom'] = TextEditingController(); - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) { - context.read().add( - ConfigureNewCbjCompEvent.sendHotSpotInformation( - cbjCompEntityInBuild, - ), - ); - - state = const ConfigureNewCbjCompState.actionInProgress(0); - - return TextAtom( - 'Configure devices', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, + switch (state) { + case ConfigureNewCbjCompState.actionInProgress: + return Column( + children: [ + const SizedBox( + height: 30, + ), + Container( + height: 35, + width: MediaQuery.of(context).size.width - 20, + decoration: const BoxDecoration( + color: Colors.black38, + borderRadius: BorderRadius.all(Radius.circular(10)), ), - ); - }, - actionInProgress: (actionInProgress) { - return Column( - children: [ - const SizedBox( - height: 30, + alignment: Alignment.center, + child: TextAtom( + 'Connecting computer to WiFi', + style: TextStyle( + fontSize: 25, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - Container( - height: 35, - width: MediaQuery.of(context).size.width - 20, - decoration: const BoxDecoration( - color: Colors.black38, - borderRadius: BorderRadius.all(Radius.circular(10)), - ), - alignment: Alignment.center, - child: TextAtom( - 'Connecting computer to WiFi', - style: TextStyle( - fontSize: 25, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - Expanded( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - height: 80, - width: 250, - child: LiquidLinearProgressIndicator( - value: actionInProgress.progressPercentage, - valueColor: - const AlwaysStoppedAnimation(Colors.pink), - backgroundColor: - Theme.of(context).textTheme.bodyLarge!.color, - borderColor: Colors.red.withOpacity(0.9), - borderWidth: 4.0, - center: const TextAtom( - 'Loading...', - style: TextStyle(color: Colors.black), - ), - borderRadius: 2, - ), - ), - const SizedBox( - height: 20, - ), - TextAtom( - 'Please wait as we are setting your new computer', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + ), + ), + Expanded( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + height: 80, + width: 250, + child: LiquidLinearProgressIndicator( + value: progressPercentage, + valueColor: const AlwaysStoppedAnimation(Colors.pink), + backgroundColor: + Theme.of(context).textTheme.bodyLarge!.color, + borderColor: Colors.red.withOpacity(0.9), + borderWidth: 4.0, + center: const TextAtom( + 'Loading...', + style: TextStyle(color: Colors.black), ), - ], + borderRadius: 2, + ), ), - ), - // child: Center( - // child: CircularProgressIndicatorAtom( - // backgroundColor: Colors.cyan, - // strokeWidth: 5, - // ), - // ), + const SizedBox( + height: 20, + ), + TextAtom( + 'Please wait as we are setting your new computer', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ], ), - ], - ); - }, - errorInProcess: (value) { - return TextAtom( - 'Error in the process.', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ); - }, - completeSuccess: (CompleteSuccess value) { - context.router.replace( - ComputerConnectionCheckRoute( - cbjCompEntity: cbjCompEntity, ), - ); - return TextAtom( - 'Computer have been configured.', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ); - }, + // child: Center( + // child: CircularProgressIndicatorAtom( + // backgroundColor: Colors.cyan, + // strokeWidth: 5, + // ), + // ), + ), + ], ); - }, - ); + + case ConfigureNewCbjCompState.errorInProcess: + return TextAtom( + 'Error in the process.', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ); + case ConfigureNewCbjCompState.completeSuccess: + return TextAtom( + 'Computer have been configured.', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ); + } } } + +enum ConfigureNewCbjCompState { + actionInProgress, + errorInProcess, + completeSuccess, + ; +} diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart index 9b2a7a8bb..0a6b6a3e3 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart @@ -1,12 +1,9 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/cbj_comp/cbj_comp_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @RoutePage() @@ -17,30 +14,26 @@ class ScanForNewCBJCompsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => - getIt()..add(const CBJCompEvent.watchAllStarted()), - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.light, - ), - body: ColoredBox( - color: Colors.black87, - child: Column( - children: [ - TopNavigationBar( - pageName: 'Add CBJ Devices', - rightIcon: null, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, - ), - Expanded( - child: ScanForNewCBJCompsWidget(), - ), - ], - ), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.light, + ), + body: ColoredBox( + color: Colors.black87, + child: Column( + children: [ + TopNavigationBar( + pageName: 'Add CBJ Devices', + rightIcon: null, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: leftIconFunction, + ), + Expanded( + child: ScanForNewCBJCompsWidget(), + ), + ], ), ), ); diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart index b6ed48e38..2362610af 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/scan_for_new_cbj_comps_widget.dart @@ -1,68 +1,102 @@ +import 'dart:async'; + import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/cbj_comp/cbj_comp_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; +import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; +import 'package:cybear_jinni/domain/cbj_comp/i_cbj_comp_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; /// Show light toggles in a container with the background color from smart room /// object -class ScanForNewCBJCompsWidget extends StatelessWidget { +class ScanForNewCBJCompsWidget extends StatefulWidget { @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => const TextAtom('Initial'), - loadInProgress: (value) { - return Column( - children: [ - const SizedBox( - height: 20, - ), - TextAtom( - 'Scanning For Devices', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 26, - ), - ), - const Expanded( - child: Center( - child: CircularProgressIndicatorAtom(), - ), - ), - ], - ); - }, - loadSuccess: (state) { - final CBJCompEntity compEntity = CBJCompEntity.empty().copyWith( - lastKnownIp: CBJCompLastKnownIp(state.securityBearIp), - ); + State createState() => + _ScanForNewCBJCompsWidgetState(); +} + +class _ScanForNewCBJCompsWidgetState extends State { + StreamSubscription>? + _cbjCompStreamSubscription; + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _cbjCompStreamSubscription?.cancel(); + _cbjCompStreamSubscription = ICBJCompRepository.instance + .getConnectedComputersIP() + .listen((failureOrCBJCompList) { + final dynamic failureOrCompListDynamic = failureOrCBJCompList.fold( + (f) => f, + (ip) => ip, + ); + + if (failureOrCompListDynamic == CBJCompFailure) { + } else { + _compDevicesReceived(failureOrCBJCompList); + } + }); + } - context.router.replace( - ConfigureNewCbjCompRoute(cbjCompEntity: compEntity), - ); + Future _compDevicesReceived( + dartz.Either failureOrCBJCompList, + ) async { + final dynamic failureOrCompListDynamic = failureOrCBJCompList.fold( + (f) => f, + (ip) => ip, + ); - return const Expanded( - child: Center( - child: CircularProgressIndicatorAtom(), - ), - ); - }, - loadSuccessTemp: (state) { - return const TextAtom('Load success temp'); - }, - loadFailure: (state) { - return const TextAtom('Load Failure'); - }, - error: (state) { - return const TextAtom('Error'); - }, - ); - }, + if (failureOrCompListDynamic == CBJCompFailure) { + } else { + final String ipAsString = failureOrCompListDynamic as String; + routeToConfigure(ipAsString); + } + } + + void routeToConfigure(String ipAsString) { + final CBJCompEntity compEntity = CBJCompEntity.empty().copyWith( + lastKnownIp: CBJCompLastKnownIp(ipAsString), + ); + + context.router.replace( + ConfigureNewCbjCompRoute(cbjCompEntity: compEntity), + ); + } + + @override + Future dispose() async { + await _cbjCompStreamSubscription?.cancel(); + await ICBJCompRepository.instance.shutdownServer(); + return super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Column( + children: [ + const SizedBox( + height: 20, + ), + TextAtom( + 'Scanning For Devices', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 26, + ), + ), + const Expanded( + child: Center( + child: CircularProgressIndicatorAtom(), + ), + ), + ], ); } } diff --git a/lib/presentation/pages/add_new_room/add_new_room_page.dart b/lib/presentation/pages/add_new_room/add_new_room_page.dart index 3faf1eb58..ecb34280c 100644 --- a/lib/presentation/pages/add_new_room/add_new_room_page.dart +++ b/lib/presentation/pages/add_new_room/add_new_room_page.dart @@ -1,10 +1,7 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/add_new_room/widgets/add_new_room_form.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; @RoutePage() class AddNewRoomPage extends StatelessWidget { @@ -15,10 +12,7 @@ class AddNewRoomPage extends StatelessWidget { backgroundColor: Colors.purple, title: const TextAtom('Add New Area'), ), - body: BlocProvider( - create: (context) => getIt(), - child: AddNewRoomForm(), - ), + body: AddNewRoomForm(), ); } } diff --git a/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart b/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart index 0a530cdba..7b6d21d24 100644 --- a/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart +++ b/lib/presentation/pages/add_new_room/widgets/add_new_room_form.dart @@ -1,146 +1,207 @@ +import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; +import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:multi_select_flutter/multi_select_flutter.dart'; -class AddNewRoomForm extends StatelessWidget { +class AddNewRoomForm extends StatefulWidget { + @override + State createState() => _AddNewRoomFormState(); +} + +class _AddNewRoomFormState extends State { + List _allRooms = []; + List _allDevices = []; + RoomUniqueId roomUniqueId = RoomUniqueId(); + RoomDefaultName cbjEntityName = RoomDefaultName(''); + RoomBackground background = RoomBackground( + 'https://live.staticflickr.com/5220/5486044345_f67abff3e9_h.jpg', + ); + RoomTypes roomTypes = RoomTypes(const []); + RoomDevicesId roomDevicesId = RoomDevicesId(const []); + RoomScenesId roomScenesId = RoomScenesId(const []); + RoomRoutinesId roomRoutinesId = RoomRoutinesId(const []); + RoomBindingsId roomBindingsId = RoomBindingsId(const []); + RoomMostUsedBy roomMostUsedBy = RoomMostUsedBy(const []); + RoomPermissions roomPermissions = RoomPermissions(const []); + bool showErrorMessages = false; + bool isSubmitting = false; + dartz.Option authFailureOrSuccessOption = dartz.none(); + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + (await IRoomRepository.instance.getAllRooms()).fold((l) => null, (r) { + _allRooms = List.from(r.iter); + }); + + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + _allDevices = List.from(r.iter); + }); + _allRooms.removeWhere((element) => element == null); + _allDevices.removeWhere((element) => element == null); + setState(() { + _allRooms = _allRooms as List; + _allDevices = _allDevices as List; + }); + } + + Future _createRoom() async { + final RoomEntity roomEntity = RoomEntity( + uniqueId: RoomUniqueId.fromUniqueString(roomUniqueId.getOrCrash()), + cbjEntityName: RoomDefaultName(cbjEntityName.getOrCrash()), + background: RoomBackground(background.getOrCrash()), + roomTypes: RoomTypes(roomTypes.getOrCrash()), + roomDevicesId: RoomDevicesId(roomDevicesId.getOrCrash()), + roomScenesId: RoomScenesId(roomScenesId.getOrCrash()), + roomRoutinesId: RoomRoutinesId(roomRoutinesId.getOrCrash()), + roomBindingsId: RoomBindingsId(roomBindingsId.getOrCrash()), + roomMostUsedBy: RoomMostUsedBy(roomMostUsedBy.getOrCrash()), + roomPermissions: RoomPermissions(roomPermissions.getOrCrash()), + ); + + IRoomRepository.instance.create(roomEntity); + } + + Future _defaultNameChanged(String value) async { + setState(() { + cbjEntityName = RoomDefaultName(value); + authFailureOrSuccessOption = dartz.none(); + }); + } + + Future _roomTypesChanged(List value) async { + setState(() { + roomTypes = RoomTypes(value); + authFailureOrSuccessOption = dartz.none(); + }); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 800), - child: Column( - children: [ - Form( - autovalidateMode: AutovalidateMode.onUserInteraction, - child: Container( - constraints: - BoxConstraints(maxHeight: screenSize.height * 0.83), - child: SingleChildScrollView( - child: Column( - children: [ - const SizedBox( - height: 70, - ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: - FaIcon(FontAwesomeIcons.rightToBracket), - labelText: 'Area Name', - ), - autocorrect: false, - onChanged: (value) => - context.read().add( - RoomSignInFormEvent.defaultNameChanged( - value, - ), - ), - validator: (_) => context - .read() - .state - .cbjEntityName - .value - .fold( - (RoomFailure f) => 'Validation error', - (r) => null, - ), - ), - const SizedBox( - height: 30, - ), - 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(), - title: const TextAtom('Select'), - items: AreaPurposesTypes.values - .map((AreaPurposesTypes areaPurposeType) { - final String tempAreaName = areaPurposeType.name - .substring(1, areaPurposeType.name.length); - String areaNameEdited = areaPurposeType.name - .substring(0, 1) - .toUpperCase(); - for (final String a in tempAreaName.characters) { - if (a[0] == a[0].toUpperCase()) { - areaNameEdited += ' '; - } - areaNameEdited += a; - } - - return MultiSelectItem( - areaPurposeType.value, - areaNameEdited, - ); - }).toList(), - listType: MultiSelectListType.CHIP, - onConfirm: (List values) { - context.read().add( - RoomSignInFormEvent.roomTypesChanged( - values.map((e) => e.toString()).toList(), - ), - ); - // _selectedAnimals = values; - }, - ), - ], - ), - ), - ), - ), - Padding( - padding: const EdgeInsets.symmetric(vertical: 5.0), - child: Row( + return Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 800), + child: Column( + children: [ + Form( + autovalidateMode: AutovalidateMode.onUserInteraction, + child: Container( + constraints: + BoxConstraints(maxHeight: screenSize.height * 0.83), + child: SingleChildScrollView( + child: Column( children: [ - Expanded( - child: TextButton( - onPressed: () { - context.read().add( - const RoomSignInFormEvent.createRoom(), - ); - Fluttertoast.showToast( - msg: 'Adding area', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.purple, - textColor: - Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - Navigator.pop(context); - }, - child: const TextAtom('ADD'), + const SizedBox( + height: 70, + ), + TextFormField( + decoration: const InputDecoration( + prefixIcon: FaIcon(FontAwesomeIcons.rightToBracket), + labelText: 'Area Name', + ), + autocorrect: false, + onChanged: (value) => _defaultNameChanged( + value, + ), + validator: (_) => cbjEntityName.value.fold( + (RoomFailure f) => 'Validation error', + (r) => null, ), ), + const SizedBox( + height: 30, + ), + 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(), + title: const TextAtom('Select'), + items: AreaPurposesTypes.values + .map((AreaPurposesTypes areaPurposeType) { + final String tempAreaName = areaPurposeType.name + .substring(1, areaPurposeType.name.length); + String areaNameEdited = areaPurposeType.name + .substring(0, 1) + .toUpperCase(); + for (final String a in tempAreaName.characters) { + if (a[0] == a[0].toUpperCase()) { + areaNameEdited += ' '; + } + areaNameEdited += a; + } + + return MultiSelectItem( + areaPurposeType.value, + areaNameEdited, + ); + }).toList(), + listType: MultiSelectListType.CHIP, + onConfirm: (List values) { + _roomTypesChanged( + values.map((e) => e.toString()).toList(), + ); + }, + ), ], ), ), - if (state.isSubmitting) ...[ - const SizedBox( - height: 8, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 5.0), + child: Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + _createRoom(); + Fluttertoast.showToast( + msg: 'Adding area', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.purple, + textColor: + Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + Navigator.pop(context); + }, + child: const TextAtom('ADD'), + ), ), - const LinearProgressIndicator(), ], - ], + ), ), - ), - ); - }, + if (isSubmitting) ...[ + const SizedBox( + height: 8, + ), + const LinearProgressIndicator(), + ], + ], + ), + ), ); } } diff --git a/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart b/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart index 18c71f584..b4458f400 100644 --- a/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart +++ b/lib/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart @@ -1,11 +1,8 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -32,10 +29,7 @@ class ChangeRoomForDevicesPage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - BlocProvider( - create: (context) => getIt(), - child: ChangeRoomForDevicesWidget(), - ), + ChangeRoomForDevicesWidget(), ], ), ); diff --git a/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart b/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart index 40db232b3..c5bc86805 100644 --- a/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart +++ b/lib/presentation/pages/change_room_for_devices/widgets/change_room_for_devices_widget.dart @@ -1,139 +1,217 @@ import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/application/room/create_new_room_form/room_sign_in_form_bloc.dart'; +import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:multi_select_flutter/multi_select_flutter.dart'; -class ChangeRoomForDevicesWidget extends StatelessWidget { +class ChangeRoomForDevicesWidget extends StatefulWidget { + @override + State createState() => + _ChangeRoomForDevicesWidgetState(); +} + +class _ChangeRoomForDevicesWidgetState + extends State { + List _allRooms = []; + List _allDevices = []; + RoomUniqueId roomUniqueId = RoomUniqueId(); + RoomDefaultName cbjEntityName = RoomDefaultName(''); + RoomBackground background = RoomBackground( + 'https://live.staticflickr.com/5220/5486044345_f67abff3e9_h.jpg', + ); + RoomTypes roomTypes = RoomTypes(const []); + RoomDevicesId roomDevicesId = RoomDevicesId(const []); + RoomScenesId roomScenesId = RoomScenesId(const []); + RoomRoutinesId roomRoutinesId = RoomRoutinesId(const []); + RoomBindingsId roomBindingsId = RoomBindingsId(const []); + RoomMostUsedBy roomMostUsedBy = RoomMostUsedBy(const []); + RoomPermissions roomPermissions = RoomPermissions(const []); + bool showErrorMessages = false; + bool isSubmitting = false; + dartz.Option authFailureOrSuccessOption = dartz.none(); + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + (await IRoomRepository.instance.getAllRooms()).fold((l) => null, (r) { + _allRooms = List.from(r.iter); + }); + + (await IDeviceRepository.instance.getAllDevices()).fold((l) => null, (r) { + _allDevices = List.from(r.iter); + }); + _allRooms.removeWhere((element) => element == null); + _allDevices.removeWhere((element) => element == null); + setState(() { + _allRooms = _allRooms as List; + _allDevices = _allDevices as List; + }); + } + + Future _changeRoomDevices() async { + final RoomEntity roomEntity = RoomEntity( + uniqueId: RoomUniqueId.fromUniqueString(roomUniqueId.getOrCrash()), + cbjEntityName: RoomDefaultName(cbjEntityName.getOrCrash()), + background: RoomBackground(background.getOrCrash()), + roomTypes: RoomTypes(roomTypes.getOrCrash()), + roomDevicesId: RoomDevicesId(roomDevicesId.getOrCrash()), + roomScenesId: RoomScenesId(roomScenesId.getOrCrash()), + roomRoutinesId: RoomRoutinesId(roomRoutinesId.getOrCrash()), + roomBindingsId: RoomBindingsId(roomBindingsId.getOrCrash()), + roomMostUsedBy: RoomMostUsedBy(roomMostUsedBy.getOrCrash()), + roomPermissions: RoomPermissions(roomPermissions.getOrCrash()), + ); + + IRoomRepository.instance.create(roomEntity); + } + + Future _roomIdChanged(String value) async { + for (final RoomEntity? roomEntity in _allRooms) { + if (roomEntity != null && roomEntity.uniqueId.getOrCrash() == value) { + setState(() { + roomUniqueId = roomEntity.uniqueId; + cbjEntityName = roomEntity.cbjEntityName; + authFailureOrSuccessOption = dartz.none(); + }); + + return; + } + } + } + + Future _roomDevicesIdChanged(List value) async { + setState(() { + roomDevicesId = RoomDevicesId(value); + authFailureOrSuccessOption = dartz.none(); + }); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - color: HexColor('#3A3A3A'), - margin: const EdgeInsets.symmetric(horizontal: 10), - child: Column( + return Container( + color: HexColor('#3A3A3A'), + margin: const EdgeInsets.symmetric(horizontal: 10), + child: Column( + children: [ + SizedBox( + height: screenSize.height * 0.05, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - SizedBox( - height: screenSize.height * 0.05, + const TextAtom( + 'Choose Area', + style: TextStyle(fontSize: 27), ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const TextAtom( - 'Choose Area', - style: TextStyle(fontSize: 27), - ), - TextButton( - onPressed: () { - context.router.push(const AddNewRoomRoute()); - }, - child: const TextAtom( - 'Add New Area', - style: TextStyle( - fontSize: 16, - color: Colors.white, - backgroundColor: Colors.blue, - ), - ), + TextButton( + onPressed: () { + context.router.push(const AddNewRoomRoute()); + }, + child: const TextAtom( + 'Add New Area', + style: TextStyle( + fontSize: 16, + color: Colors.white, + backgroundColor: Colors.blue, ), - ], - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - state.cbjEntityName.isValid() - ? state.cbjEntityName.getOrCrash() - : 'Choose Area', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, ), - onChanged: (value) { - context - .read() - .add(RoomSignInFormEvent.roomIdChanged(value!)); - }, - items: state.allRooms.map>((e) { - // .map>((String value) { - return DropdownMenuItem( - value: e.uniqueId.getOrCrash(), - child: TextAtom(e.cbjEntityName.getOrCrash()), - ); - }).toList(), - ), - SizedBox( - height: screenSize.height * 0.1, ), - const Row( - children: [ - TextAtom( - 'Choose Device', - style: TextStyle(fontSize: 27), - ), - ], + ], + ), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + cbjEntityName.isValid() + ? cbjEntityName.getOrCrash() + : 'Choose Area', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) { + _roomIdChanged(value!); + }, + items: _allRooms.map>((e) { + // .map>((String value) { + return DropdownMenuItem( + value: e?.uniqueId.getOrCrash(), + child: TextAtom(e?.cbjEntityName.getOrCrash() ?? ''), + ); + }).toList(), + ), + SizedBox( + height: screenSize.height * 0.1, + ), + const Row( + children: [ + TextAtom( + 'Choose Device', + style: TextStyle(fontSize: 27), ), - Container( - constraints: BoxConstraints(maxHeight: screenSize.height * 0.5), - child: SingleChildScrollView( - child: MultiSelectDialogField( - items: List>.of( - state.allDevices.map( - (e) => MultiSelectItem( - e.uniqueId.getOrCrash(), - e.cbjEntityName.getOrCrash()!, - ), - ), + ], + ), + Container( + constraints: BoxConstraints(maxHeight: screenSize.height * 0.5), + child: SingleChildScrollView( + child: MultiSelectDialogField( + items: List>.of( + _allDevices.map( + (e) => MultiSelectItem( + e?.uniqueId.getOrCrash(), + e?.cbjEntityName.getOrCrash()! ?? '', ), - listType: MultiSelectListType.CHIP, - onConfirm: (List values) { - context.read().add( - RoomSignInFormEvent.roomDevicesIdChanged( - List.from(values), - ), - ); - }, ), ), + listType: MultiSelectListType.CHIP, + onConfirm: (List values) { + _roomDevicesIdChanged( + List.from(values), + ); + }, ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () { - Fluttertoast.showToast( - msg: 'Changing devices for area', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.purple, - textColor: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - context.read().add( - RoomSignInFormEvent.changeRoomDevices(context), - ); - }, - child: const TextAtom( - 'Done', - style: TextStyle(fontSize: 20), - ), - ), - ], + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () { + Fluttertoast.showToast( + msg: 'Changing devices for area', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.purple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _changeRoomDevices(); + }, + child: const TextAtom( + 'Done', + style: TextStyle(fontSize: 20), + ), ), ], ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart index 4b8e5abd8..e053c96aa 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/blinds/blinds_watcher/blinds_watcher_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; @@ -45,10 +44,6 @@ class RoomsBlindsPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const BlindsWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart index 3845e1f00..9fe2743b9 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart @@ -1,24 +1,58 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show light toggles in a container with the background color from smart room /// object -class BlindWidget extends StatelessWidget { +class BlindWidget extends StatefulWidget { const BlindWidget(this._deviceEntity); final GenericBlindsDE _deviceEntity; + @override + State createState() => _BlindWidgetState(); +} + +class _BlindWidgetState extends State { + Future _moveUpAllBlinds(List blindsIdToTurnUp) async { + FlushbarHelper.createLoading( + message: 'Pulling_Up_all_blinds'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.moveUpStateDevices(devicesId: blindsIdToTurnUp); + } + + Future _stopAllBlinds(List blindsIdToStop) async { + FlushbarHelper.createLoading( + message: 'Stopping_all_blinds'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.stopStateDevices(devicesId: blindsIdToStop); + } + + Future _moveDownAllBlinds(List blindsIdToTurnDown) async { + FlushbarHelper.createLoading( + message: 'Pulling_down_all_blinds'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance + .moveDownStateDevices(devicesId: blindsIdToTurnDown); + } + @override Widget build(BuildContext context) { // final Size screenSize = MediaQuery.of(context).size; - final deviceState = _deviceEntity.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity.blindsSwitchState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.blindsSwitchState!.getOrCrash(); // bool toggleValue = false; // Color toggleColor = Colors.blueGrey; @@ -34,136 +68,121 @@ class BlindWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Column( + return Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox( - width: 10, + const SizedBox( + width: 10, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.brown, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.brown, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), - onPressed: () { - context.read().add( - BlindsActorEvent.moveDownAllBlinds( - [_deviceEntity.uniqueId.getOrCrash()], - context, - ), - ); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.arrowDown, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Down', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), ), ), - const SizedBox( - width: 10, + ), + onPressed: () { + _moveDownAllBlinds( + [widget._deviceEntity.uniqueId.getOrCrash()], + ); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.arrowDown, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + child: TextAtom( + 'Down', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), - onPressed: () { - context.read().add( - BlindsActorEvent.stopAllBlinds( - [_deviceEntity.uniqueId.getOrCrash()], - context, - ), - ); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.solidHand, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Stop', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), ), ), - const SizedBox( - width: 10, + ), + ), + const SizedBox( + width: 10, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, + ), + ), + ), + onPressed: () { + _stopAllBlinds([widget._deviceEntity.uniqueId.getOrCrash()]); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.solidHand, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Stop', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, + ), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.amber, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + ), + ), + const SizedBox( + width: 10, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.amber, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), - onPressed: () { - context.read().add( - BlindsActorEvent.moveUpAllBlinds( - [_deviceEntity.uniqueId.getOrCrash()], - context, - ), - ); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.arrowUp, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Up', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), ), ), - const SizedBox( - width: 10, + ), + onPressed: () { + _moveUpAllBlinds([widget._deviceEntity.uniqueId.getOrCrash()]); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.arrowUp, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Up', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, + ), ), - ], + ), ), const SizedBox( - height: 20, + width: 10, ), ], - ); - }, + ), + const SizedBox( + height: 20, + ), + ], ); } } diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart index 4ba499642..3043580e0 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart @@ -1,12 +1,9 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/blind_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -60,10 +57,7 @@ class RoomBlinds extends StatelessWidget { ), Container( margin: const EdgeInsets.symmetric(vertical: 5), - child: BlocProvider( - create: (context) => getIt(), - child: BlindWidget(deviceEntityTemp), - ), + child: BlindWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart index 3344a59cc..72fb76a58 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart @@ -1,14 +1,17 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/blinds/blinds_watcher/blinds_watcher_bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/critical_failure_blinds_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/widgets/room_blinds.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsBlindsWidget extends StatelessWidget { +class RoomsBlindsWidget extends StatefulWidget { const RoomsBlindsWidget({ required this.roomEntity, required this.roomColorGradiant, @@ -17,109 +20,130 @@ class RoomsBlindsWidget extends StatelessWidget { final RoomEntity roomEntity; final List roomColorGradiant; + @override + State createState() => _RoomsBlindsWidgetState(); +} + +class _RoomsBlindsWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + KtList devices = const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = IDeviceRepository.instance.watchBlinds().listen( + (eventWatch) => _blindsReceived(eventWatch), + ); + } + + Future _blindsReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d.map((v) => v! as GenericBlindsDE).toMutableList(), + ); + + setState(() { + devices = devicesTemp; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - - final KtList devicesInRoom = - devicesByRooms[index]; - - return RoomBlinds( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxLightsToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Blinds does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], + if (devices.isNotEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'Blinds does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } - }, - loadFailure: (state) { - return CriticalFailureBlindsDisplay( - failure: state.devicesFailure, - ); - }, - blindError: (BlindError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + + final KtList devicesInRoom = + devicesByRooms[index]; + + return RoomBlinds( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxLightsToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart index 89bd84ccd..8369726f2 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart @@ -1,7 +1,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; @@ -45,10 +44,6 @@ class RoomsBoilersPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const BoilersWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart index 23d7c043a..b8ab9a45d 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart @@ -1,33 +1,47 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cybear_jinni/application/boilers/boilers_actor/boilers_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show boiler toggles in a container with the background color from smart room /// object -class BoilersWidget extends StatelessWidget { +class BoilersWidget extends StatefulWidget { const BoilersWidget(this._deviceEntity); final GenericBoilerDE _deviceEntity; - void _onChange(BuildContext context, bool value) { + @override + State createState() => _BoilersWidgetState(); +} + +class _BoilersWidgetState extends State { + Future _turnOnAllBoilers(List boilersIdToTurnUp) async { + FlushbarHelper.createLoading( + message: 'Turning_On_boiler'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOnDevices(devicesId: boilersIdToTurnUp); + } + + Future _turnOffAllBoilers(List boilersIdToTurnOff) async { + FlushbarHelper.createLoading( + message: 'Turning_Off_boiler'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOffDevices(devicesId: boilersIdToTurnOff); + } + + void _onChange(bool value) { if (value) { - context.read().add( - BoilersActorEvent.turnOnAllBoilers( - [_deviceEntity.uniqueId.getOrCrash()], - context, - ), - ); + _turnOnAllBoilers([widget._deviceEntity.uniqueId.getOrCrash()]); } else { - context.read().add( - BoilersActorEvent.turnOffAllBoilers( - [_deviceEntity.uniqueId.getOrCrash()], - context, - ), - ); + _turnOffAllBoilers([widget._deviceEntity.uniqueId.getOrCrash()]); } } @@ -36,8 +50,8 @@ class BoilersWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity.boilerSwitchState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.boilerSwitchState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -53,44 +67,35 @@ class BoilersWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.temperatureThreeQuarters, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.temperatureThreeQuarters, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(context, value) - // _onChange(context, value), - - , + return Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.temperatureThreeQuarters, + color: Color(0xFFF8E3A1), + ), + inactiveIcon: Icon( + FontAwesomeIcons.temperatureThreeQuarters, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - }, + onToggle: (bool value) => _onChange(value)), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart index a06400b6e..766984c5f 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cybear_jinni/application/boilers/boilers_actor/boilers_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/error_boilers_device_card_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -75,13 +72,9 @@ class RoomBoilers extends StatelessWidget { height: 3, ), Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: BoilersWidget(deviceEntityTemp), - ), - ), + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: BoilersWidget(deviceEntityTemp)), ], ), ); diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart index 334e31c50..fc6624a5a 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart @@ -1,14 +1,17 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/boilers/boilers_watcher/boilers_watcher_bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/critical_boilers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsBoilersWidget extends StatelessWidget { +class RoomsBoilersWidget extends StatefulWidget { const RoomsBoilersWidget({ required this.roomEntity, required this.roomColorGradiant, @@ -17,108 +20,130 @@ class RoomsBoilersWidget extends StatelessWidget { final RoomEntity roomEntity; final List roomColorGradiant; + @override + State createState() => _RoomsBoilersWidgetState(); +} + +class _RoomsBoilersWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + KtList devices = const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchBoilers().listen( + (eventWatch) => _boilersReceived(eventWatch), + ); + } + + Future _boilersReceived( + dartz.Either, KtList> + failureOrDevices) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d.map((v) => v! as GenericBoilerDE).toMutableList(), + ); + + setState(() { + devices = devicesTemp; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - - final devicesInRoom = devicesByRooms[index]; - - return RoomBoilers( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxBoilersToShow: 50, - ); - }, - itemCount: devicesByRooms.length, + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'Boilers does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Boilers does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], - ), - ); - } - }, - loadFailure: (state) { - return CriticalBoilersFailureDisplay( - failure: state.devicesFailure, - ); - }, - boilerError: (value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + + final devicesInRoom = devicesByRooms[index]; + + return RoomBoilers( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxBoilersToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart index c9f80d04d..079d9a1c0 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -43,10 +42,6 @@ class RoomsLightsPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const LightsWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart index 7a19d2af3..c932454a7 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/rooms_lights_widget.dart @@ -1,16 +1,17 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/lights/lights_watcher/lights_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsLightsWidget extends StatelessWidget { +class RoomsLightsWidget extends StatefulWidget { const RoomsLightsWidget({ required this.roomEntity, required this.roomColorGradiant, @@ -19,110 +20,136 @@ class RoomsLightsWidget extends StatelessWidget { final RoomEntity roomEntity; final ListOfColors roomColorGradiant; + @override + State createState() => _RoomsLightsWidgetState(); +} + +class _RoomsLightsWidgetState extends State { + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + bool inProgress = true; + KtList devices = + [].toImmutableList(); + + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = IDeviceRepository.instance.watchLights().listen( + (eventWatch) => _devicesReceived(eventWatch), + ); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + devices = failureOrDevices.fold( + (f) => [].toImmutableList(), + (d) => d.map((v) => v!).toMutableList(), + ); + setState(() { + inProgress = false; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('Lights loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = - roomColorGradiant.listOfColors!; - - final devicesInRoom = devicesByRooms[index]; - - return RoomLights( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxLightsToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Lights does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], - ), - ); - } - }, - loadFailure: (state) { - return CriticalLightFailureDisplay( - failure: state.devicesFailure, + if (inProgress) { + return const CircularProgressIndicator(); + } + + if (devices.size != 0) { + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = + widget.roomColorGradiant.listOfColors!; + + final devicesInRoom = devicesByRooms[index]; + + return RoomLights( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxLightsToShow: 50, ); }, - lightError: (LightError value) { - return const TextAtom('Error'); - }, - ); - }, - ); + itemCount: devicesByRooms.length, + ), + ); + } else { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'Lights does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ], + ), + ); + } } } diff --git a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart index 14d26eb3a..ea4d7e1b5 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -46,10 +45,6 @@ class RoomsPrintersPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const PrintersWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart index e5f983990..12a716ab6 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart @@ -1,86 +1,80 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; -import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:url_launcher/url_launcher.dart'; /// Show switch toggles in a container with the background color from smart room /// object -class PrinterWidget extends StatelessWidget { +class PrinterWidget extends StatefulWidget { const PrinterWidget(this._deviceEntity); - final GenericPrinterDE? _deviceEntity; + final GenericPrinterDE _deviceEntity; - void openPrintersWebPage(BuildContext context) { - _deviceEntity!.getDeviceId(); - context.read().add( - PrintersActorEvent.openPrintersWebPage( - _deviceEntity!, - context, - ), - ); - } + @override + State createState() => _PrinterWidgetState(); +} - void shutdownComputer(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); - context.read().add( - PrintersActorEvent.shutdownAllPrinters( - [deviceId], - context, - ), - ); +class _PrinterWidgetState extends State { + Future _openPrintersWebPage() async { + FlushbarHelper.createLoading( + message: 'Opening printers Web Page', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + final String printerIp = + widget._deviceEntity.deviceLastKnownIp.getOrCrash(); + launchUrl( + Uri.parse('http://$printerIp'), + mode: LaunchMode.externalApplication, + ); } @override Widget build(BuildContext context) { - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Column( + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), - onPressed: () { - openPrintersWebPage(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.link, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - "Open Printer's Web Page", - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + ), + ), + onPressed: () { + _openPrintersWebPage(); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.link, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + "Open Printer's Web Page", + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), ), - ], - ), - const SizedBox( - height: 20, + ), ), ], - ); - }, + ), + const SizedBox( + height: 20, + ), + ], ); } } diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart index f2aa40056..1dc40f386 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_printer_device/generic_printer_entity.dart'; -import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/error_printers_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/printer_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -67,10 +64,7 @@ class RoomPrinters extends StatelessWidget { ), Container( margin: const EdgeInsets.symmetric(vertical: 5), - child: BlocProvider( - create: (context) => getIt(), - child: PrinterWidget(deviceEntityTemp), - ), + child: PrinterWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart index 437560cfa..94396bc5a 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/widgets/rooms_printers_widget.dart @@ -1,15 +1,16 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/printers/printers_watcher/printers_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/room_printers.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsPrintersWidget extends StatelessWidget { +class RoomsPrintersWidget extends StatefulWidget { const RoomsPrintersWidget( this.roomEntity, this.roomColorGradiant, @@ -20,108 +21,129 @@ class RoomsPrintersWidget extends StatelessWidget { final List roomColorGradiant; + @override + State createState() => _RoomsPrintersWidgetState(); +} + +class _RoomsPrintersWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + KtList devices = + const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchPrinters().listen( + (eventWatch) => _devicesReceived(eventWatch), + ); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d.map((v) => v!).toMutableList(), + ); + + setState(() { + devices = devicesTemp; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('Printers loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - final devicesInRoom = devicesByRooms[index]; - - return RoomPrinters( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxPrintersToShow: 50, - ); - }, - itemCount: devicesByRooms.length, + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'Printers does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Printers does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], - ), - ); - } - }, - loadFailure: (state) { - return CriticalSwitchFailureDisplay( - failure: state.devicesFailure, - ); - }, - printersError: (PrintersError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; + + return RoomPrinters( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxPrintersToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart index 4cc20c40f..9046d3302 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -46,10 +45,6 @@ class RoomsSmartComputersPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const SmartComputersWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart index aab3e729d..32c797182 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; -import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/error_smart_computers_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -71,10 +68,7 @@ class RoomSmartComputers extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: SmartComputerWidget(deviceEntityTemp), - ), + child: SmartComputerWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart index 40ecefc69..159a27167 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/rooms_smart_computers_widget.dart @@ -1,15 +1,16 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/smart_computers/smart_computers_watcher/smart_computer_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/critical_smart_computers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/widgets/room_smart_computers.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsSmartComputersWidget extends StatelessWidget { +class RoomsSmartComputersWidget extends StatefulWidget { const RoomsSmartComputersWidget( this.roomEntity, this.roomColorGradiant, @@ -20,109 +21,131 @@ class RoomsSmartComputersWidget extends StatelessWidget { final List roomColorGradiant; + @override + State createState() => + _RoomsSmartComputersWidgetState(); +} + +class _RoomsSmartComputersWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + KtList devices = + const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSmartComputers().listen( + (eventWatch) => _devicesReceived(eventWatch), + ); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtMutableList tempDevice = + failureOrDevices.fold( + (f) => KtMutableList.empty(), + (d) => d.map((v) => v!).toMutableList(), + ); + setState(() { + devices = tempDevice; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('SmartComputers loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - - final devicesInRoom = devicesByRooms[index]; - - return RoomSmartComputers( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxSmartComputersToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'SmartComputers does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'SmartComputers does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } - }, - loadFailure: (state) { - return CriticalSwitchFailureDisplay( - failure: state.devicesFailure, - ); - }, - smartComputersError: (SmartComputersError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + + final devicesInRoom = devicesByRooms[index]; + + return RoomSmartComputers( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxSmartComputersToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart index 0a1c02fef..3ccf3a28a 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/widgets/smart_computer_widget.dart @@ -1,119 +1,127 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; -import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show switch toggles in a container with the background color from smart room /// object -class SmartComputerWidget extends StatelessWidget { +class SmartComputerWidget extends StatefulWidget { const SmartComputerWidget(this._deviceEntity); final GenericSmartComputerDE? _deviceEntity; + @override + State createState() => _SmartComputerWidgetState(); +} + +class _SmartComputerWidgetState extends State { + Future _suspendAllSmartComputers(List smartComputersId) async { + FlushbarHelper.createLoading( + message: 'Suspending all Smart Computers', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.suspendDevices(devicesId: smartComputersId); + } + + Future _shutdownAllSmartComputers(List smartComputersId) async { + FlushbarHelper.createLoading( + message: 'Suspending all Smart Computers', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.shutdownDevices(devicesId: smartComputersId); + } + void suspendComputer(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); - context.read().add( - SmartComputersActorEvent.suspendAllSmartComputers( - [deviceId], - context, - ), - ); + final String deviceId = widget._deviceEntity!.getDeviceId(); + _suspendAllSmartComputers([deviceId]); } void shutdownComputer(BuildContext context) { - final String deviceId = _deviceEntity!.getDeviceId(); - context.read().add( - SmartComputersActorEvent.shutdownAllSmartComputers( - [deviceId], - context, - ), - ); + final String deviceId = widget._deviceEntity!.getDeviceId(); + _shutdownAllSmartComputers([deviceId]); } @override Widget build(BuildContext context) { - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Column( + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), - ), - onPressed: () { - suspendComputer(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.moon, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Sleep', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), ), - const SizedBox( - width: 10, + ), + onPressed: () { + suspendComputer(context); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.moon, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), - ), - onPressed: () { - shutdownComputer(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.powerOff, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Shutdown', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + child: TextAtom( + 'Sleep', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), ), - ], + ), ), const SizedBox( - height: 20, + width: 10, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, + ), + ), + ), + onPressed: () { + shutdownComputer(context); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.powerOff, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Shutdown', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, + ), + ), + ), ), ], - ); - }, + ), + const SizedBox( + height: 20, + ), + ], ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart index 01a39ea74..c786c714f 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -46,10 +45,6 @@ class RoomsSmartPlugsPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const SmartPlugsWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart index 29f4fd282..85ad6cf35 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; -import 'package:cybear_jinni/application/smart_plug_toggle/smart_plug_toggle_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/error_smart_plugs_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -69,10 +66,7 @@ class RoomSmartPlugs extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: SmartPlugWidget(deviceEntityTemp), - ), + child: SmartPlugsWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart index a841d9663..8a7eefcc2 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart @@ -1,15 +1,16 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/smart_plugs/smart_plugs_watcher/smart_plugs_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/critical_smart_plugs_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/widgets/room_smart_plugs.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsSmartPlugsWidget extends StatelessWidget { +class RoomsSmartPlugsWidget extends StatefulWidget { const RoomsSmartPlugsWidget( this.roomEntity, this.roomColorGradiant, @@ -20,109 +21,130 @@ class RoomsSmartPlugsWidget extends StatelessWidget { final List roomColorGradiant; + @override + State createState() => _RoomsSmartPlugsWidgetState(); +} + +class _RoomsSmartPlugsWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + + KtList devices = + const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSmartPlugs().listen( + (eventWatch) => _devicesReceived(eventWatch), + ); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d.map((v) => v!).toMutableList(), + ); + setState(() { + devices = devicesTemp; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('SmartPlugs loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - final devicesInRoom = devicesByRooms[index]; - - return RoomSmartPlugs( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxSmartPlugsToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'SmartPlugs does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'SmartPlugs does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } - }, - loadFailure: (state) { - return CriticalSmartPlugFailureDisplay( - failure: state.devicesFailure, - ); - }, - smartPlugsError: (SmartPlugsError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + final devicesInRoom = devicesByRooms[index]; + + return RoomSmartPlugs( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxSmartPlugsToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart index 5415069f5..a543f6916 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/smart_plugs_widget.dart @@ -1,22 +1,59 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; -import 'package:cybear_jinni/application/smart_plug_toggle/smart_plug_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; /// Show smartPlug toggles in a container with the background color from smart room /// object -class SmartPlugWidget extends StatelessWidget { - const SmartPlugWidget(this._deviceEntity); +class SmartPlugsWidget extends StatefulWidget { + const SmartPlugsWidget(this._deviceEntity); + + final GenericSmartPlugDE _deviceEntity; - final GenericSmartPlugDE? _deviceEntity; + @override + State createState() => _SmartPlugsWidgetState(); +} - void _onChange(BuildContext context, bool value) { - context.read().add( - SmartPlugToggleEvent.changeAction(_deviceEntity!, value), - ); +class _SmartPlugsWidgetState extends State { + int sendNewColorEachMilliseconds = 200; + Timer? timeFromLastColorChange; + HSVColor? lastColoredPicked; + + Future _changeAction( + bool changeToState, + DeviceEntityAbstract deviceEntity, + ) async { + dartz.Either actionResult; + + if (changeToState) { + actionResult = await IDeviceRepository.instance.turnOnDevices( + devicesId: [deviceEntity.uniqueId.getOrCrash()], + ); + } else { + actionResult = await IDeviceRepository.instance.turnOffDevices( + devicesId: [deviceEntity.uniqueId.getOrCrash()], + ); + + actionResult.fold((devicesFailure) {}, (_) {}); + } + } + + /// This function will make sure that the app sends color once each x seconds. + /// Moving the hand on the color slider sends tons of requests with + /// different colors which is not efficient and some device can't even handle + /// so many requests. + Future changeColorOncePerTimer() async { + await IDeviceRepository.instance.changeHsvColorDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + hsvColorToChange: lastColoredPicked!, + ); } @override @@ -24,8 +61,8 @@ class SmartPlugWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity!.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity!.smartPlugState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.smartPlugState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -41,44 +78,36 @@ class SmartPlugWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: Icon( - MdiIcons.powerSocketAu, - color: Colors.white, - ), - inactiveIcon: Icon( - MdiIcons.powerSocketAu, - color: Colors.white70, - ), - onToggle: (bool value) => _onChange(context, value) - // _onChange(context, value), - - , - ), - ); - }, + return Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: Icon( + MdiIcons.powerSocketAu, + color: Colors.white, + ), + inactiveIcon: Icon( + MdiIcons.powerSocketAu, + color: Colors.white70, + ), + onToggle: (bool value) => _changeAction(value, widget._deviceEntity), + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart index 1f2b6b86c..2e5cdb72a 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -46,10 +45,6 @@ class RoomsSmartTvsPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const SmartTvWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart index b914d8319..bab44f568 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart @@ -1,8 +1,8 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; class OpenUrlPopUp { OpenUrlPopUp(this.contextFromParent, this._deviceEntity) { @@ -84,12 +84,13 @@ class OpenUrlPopUp { void playVideo(BuildContext context, String url) { final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.openUrl( - context, - [deviceId], - url, - ), - ); + FlushbarHelper.createLoading( + message: 'Open url on smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + IDeviceRepository.instance.openUrlOnDevices( + devicesId: [deviceId], + url: url, + ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart index 58bc1dd52..fb4ecaee1 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/error_smart_tvs_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -68,10 +65,7 @@ class RoomSmartTvs extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 5), // width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: SmartTvWidget(deviceEntityTemp), - ), + child: SmartTvWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart index 5f9b8436b..ae3bc9b0e 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/rooms_smart_tvs_widget.dart @@ -1,15 +1,17 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_watcher/smart_tv_watcher_bloc.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/widgets/critical_printers_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/room_smart_tvs.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsSmartTvsWidget extends StatelessWidget { +class RoomsSmartTvsWidget extends StatefulWidget { const RoomsSmartTvsWidget( this.roomEntity, this.roomColorGradiant, @@ -20,109 +22,131 @@ class RoomsSmartTvsWidget extends StatelessWidget { final List roomColorGradiant; + @override + State createState() => _RoomsSmartTvsWidgetState(); +} + +class _RoomsSmartTvsWidgetState extends State { + KtList devices = const KtList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSmartTv().listen( + (eventWatch) => _smartTvReceived(eventWatch), + ); + } + + Future _smartTvReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d.map((v) => v! as GenericSmartTvDE).toMutableList(), + ); + + setState(() { + devices = devicesTemp; + }); + } + + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('SmartTvs loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - - final devicesInRoom = devicesByRooms[index]; - - return RoomSmartTvs( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxSmartTvsToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'SmartTvs does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'SmartTvs does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } - }, - loadFailure: (state) { - return CriticalSwitchFailureDisplay( - failure: state.devicesFailure, - ); - }, - smartTvsError: (SmartTvsError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + + final devicesInRoom = devicesByRooms[index]; + + return RoomSmartTvs( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxSmartTvsToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart index 3e48bd8b1..af7005d3d 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/widgets/smart_tv_widget.dart @@ -1,306 +1,302 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/widgets/open_url_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show switch toggles in a container with the background color from smart room /// object -class SmartTvWidget extends StatelessWidget { +class SmartTvWidget extends StatefulWidget { const SmartTvWidget(this._deviceEntity); final GenericSmartTvDE _deviceEntity; - void stopState(BuildContext context) { - final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.stopEvent( - [deviceId], - context, - ), - ); + @override + State createState() => _SmartTvWidgetState(); +} + +class _SmartTvWidgetState extends State { + Future _stopState() async { + FlushbarHelper.createLoading( + message: 'Stop smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance + .stopStateDevices(devicesId: [widget._deviceEntity.getDeviceId()]); } - // void pauseEvent(BuildContext context) { - // final String deviceId = _deviceEntity!.getDeviceId(); - // context.read().add( - // SmartTvActorEvent.pauseEvent( - // [deviceId], - // context, - // ), - // ); - // } - void closeEvent(BuildContext context) { - final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.closeEvent( - [deviceId], - context, - ), - ); + Future _playState() async { + FlushbarHelper.createLoading( + message: 'Play smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance + .playStateDevices(devicesId: [widget._deviceEntity.getDeviceId()]); + } + + Future _queuePrevEvent(List smartTvId) async { + FlushbarHelper.createLoading( + message: 'Change volume smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.queuePrevStateDevices(devicesId: smartTvId); } - void playEvent(BuildContext context) { - final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.playEvent( - [deviceId], - context, - ), - ); + Future _queueNextEvent(List smartTvId) async { + FlushbarHelper.createLoading( + message: 'Change volume smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.queueNextStateDevices(devicesId: smartTvId); + } + + void closeEvent(BuildContext context) { + final String deviceId = widget._deviceEntity.getDeviceId(); + + FlushbarHelper.createLoading( + message: 'Close current app on smart tv', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.closeStateDevices(devicesId: [deviceId]); } void queueNextEvent(BuildContext context) { - final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.queueNextEvent( - [deviceId], - context, - ), - ); + final String deviceId = widget._deviceEntity.getDeviceId(); + _queueNextEvent([deviceId]); } void queuePrevEvent(BuildContext context) { - final String deviceId = _deviceEntity.getDeviceId(); - context.read().add( - SmartTvActorEvent.queuePrevEvent( - [deviceId], - context, - ), - ); + final String deviceId = widget._deviceEntity.getDeviceId(); + _queuePrevEvent([deviceId]); } @override Widget build(BuildContext context) { - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Column( + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), - ), - onPressed: () { - // TextField( - // decoration: InputDecoration( - // border: OutlineInputBorder(), - // hintText: 'Enter a search term', - // ), - // ); - OpenUrlPopUp( - context, - _deviceEntity, - ); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.video, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Open Video', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), ), - const SizedBox( - width: 10, + ), + onPressed: () { + // TextField( + // decoration: InputDecoration( + // border: OutlineInputBorder(), + // hintText: 'Enter a search term', + // ), + // ); + OpenUrlPopUp( + context, + widget._deviceEntity, + ); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.video, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), - ), - onPressed: () { - stopState(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.xmark, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Close', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + child: TextAtom( + 'Open Video', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), ), - const SizedBox( - width: 5, + ), + ), + const SizedBox( + width: 10, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), - onPressed: () { - closeEvent(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.pause, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Pause', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + ), + ), + onPressed: _stopState, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.xmark, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Close', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), ), - const SizedBox( - width: 5, + ), + ), + const SizedBox( + width: 5, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey, - ), - side: MaterialStateProperty.all( - BorderSide.lerp( - const BorderSide(color: Colors.white60), - const BorderSide(color: Colors.white60), - 22, - ), - ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, ), - onPressed: () { - playEvent(context); - }, - child: Tab( - icon: FaIcon( - FontAwesomeIcons.play, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - child: TextAtom( - 'Play', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16, - ), - ), + ), + ), + onPressed: () { + closeEvent(context); + }, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.pause, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Pause', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, ), ), - ], + ), ), const SizedBox( - height: 20, + width: 5, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey, + ), + side: MaterialStateProperty.all( + BorderSide.lerp( + const BorderSide(color: Colors.white60), + const BorderSide(color: Colors.white60), + 22, + ), + ), + ), + onPressed: _playState, + child: Tab( + icon: FaIcon( + FontAwesomeIcons.play, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + child: TextAtom( + 'Play', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16, + ), + ), + ), ), - // Next and previous does not seep to currently work for me on Chromecast - // Row( - // mainAxisAlignment: MainAxisAlignment.center, - // children: [ - // TextButton( - // style: ButtonStyle( - // backgroundColor: MaterialStateProperty.all( - // Colors.grey, - // ), - // side: MaterialStateProperty.all( - // BorderSide.lerp( - // const BorderSide(color: Colors.white60), - // const BorderSide(color: Colors.white60), - // 22, - // ), - // ), - // ), - // onPressed: () { - // queueNextEvent( - // context, - // ); - // }, - // child: Tab( - // icon: FaIcon( - // FontAwesomeIcons.backwardStep, - // color: Theme.of(context).textTheme.bodyLarge!.color, - // ), - // child: TextAtom( - // 'Queue Prev', - // style: TextStyle( - // color: Theme.of(context).textTheme.bodyLarge!.color, - // fontSize: 16, - // ), - // ), // ), - // ), - // const SizedBox(width: 10), - // TextButton( - // style: ButtonStyle( - // backgroundColor: MaterialStateProperty.all( - // Colors.grey, - // ), - // side: MaterialStateProperty.all( - // BorderSide.lerp( - // const BorderSide(color: Colors.white60), - // const BorderSide(color: Colors.white60), - // 22, - // ), - // ), - // ), - // onPressed: () { - // queueNextEvent( - // context, - // ); - // }, - // child: Tab( - // icon: FaIcon( - // FontAwesomeIcons.forwardStep, - // color: Theme.of(context).textTheme.bodyLarge!.color, - // ), - // child: TextAtom( - // 'Queue Next', - // style: TextStyle( - // color: Theme.of(context).textTheme.bodyLarge!.color, - // fontSize: 16, - // ), - // ), // ), - // ), - // ], - // ), - // const SizedBox( - // height: 20, - // ), ], - ); - }, + ), + const SizedBox( + height: 20, + ), + // Next and previous does not seep to currently work for me on Chromecast + // Row( + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // TextButton( + // style: ButtonStyle( + // backgroundColor: MaterialStateProperty.all( + // Colors.grey, + // ), + // side: MaterialStateProperty.all( + // BorderSide.lerp( + // const BorderSide(color: Colors.white60), + // const BorderSide(color: Colors.white60), + // 22, + // ), + // ), + // ), + // onPressed: () { + // queueNextEvent( + // context, + // ); + // }, + // child: Tab( + // icon: FaIcon( + // FontAwesomeIcons.backwardStep, + // color: Theme.of(context).textTheme.bodyLarge!.color, + // ), + // child: TextAtom( + // 'Queue Prev', + // style: TextStyle( + // color: Theme.of(context).textTheme.bodyLarge!.color, + // fontSize: 16, + // ), + // ), // ), + // ), + // const SizedBox(width: 10), + // TextButton( + // style: ButtonStyle( + // backgroundColor: MaterialStateProperty.all( + // Colors.grey, + // ), + // side: MaterialStateProperty.all( + // BorderSide.lerp( + // const BorderSide(color: Colors.white60), + // const BorderSide(color: Colors.white60), + // 22, + // ), + // ), + // ), + // onPressed: () { + // queueNextEvent( + // context, + // ); + // }, + // child: Tab( + // icon: FaIcon( + // FontAwesomeIcons.forwardStep, + // color: Theme.of(context).textTheme.bodyLarge!.color, + // ), + // child: TextAtom( + // 'Queue Next', + // style: TextStyle( + // color: Theme.of(context).textTheme.bodyLarge!.color, + // fontSize: 16, + // ), + // ), // ), + // ), + // ], + // ), + // const SizedBox( + // height: 20, + // ), + ], ); } } diff --git a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart index b51b25735..7be96c9c2 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart @@ -2,7 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/switches/switches_watcher/switches_watcher_bloc.dart'; import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; @@ -46,10 +45,6 @@ class RoomsSwitchesPage extends StatelessWidget { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ - BlocProvider( - create: (context) => getIt() - ..add(const SwitchesWatcherEvent.watchAllStarted()), - ), BlocProvider( create: (context) => getIt(), ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart index fd27aa7cd..8fcf9a103 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart @@ -1,13 +1,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/application/switch_toggle/switch_toggle_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/error_switches_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -69,10 +66,7 @@ class RoomSwitches extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: SwitchWidget(deviceEntityTemp), - ), + child: SwitchWidget(deviceEntityTemp), ), ], ), diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart index 5ee752301..5479a86e8 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/rooms_switches_widget.dart @@ -1,15 +1,16 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/switches/switches_watcher/switches_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/critical_switches_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/widgets/room_switches.dart'; -import 'package:cybear_jinni/utils.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; -class RoomsSwitchesWidget extends StatelessWidget { +class RoomsSwitchesWidget extends StatefulWidget { const RoomsSwitchesWidget( this.roomEntity, this.roomColorGradiant, @@ -20,109 +21,133 @@ class RoomsSwitchesWidget extends StatelessWidget { final List roomColorGradiant; + @override + State createState() => _RoomsSwitchesWidgetState(); +} + +class _RoomsSwitchesWidgetState extends State { + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + + KtMutableList devices = + KtMutableList.empty(); + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + await _deviceStreamSubscription?.cancel(); + _deviceStreamSubscription = + IDeviceRepository.instance.watchSwitches().listen( + (eventWatch) => _devicesReceived(eventWatch), + ); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtMutableList devicesTemp = + failureOrDevices.fold( + (f) => KtMutableList.empty(), + (d) => d.map((v) => v!).toMutableList(), + ); + + setState(() { + devices = devicesTemp; + }); + } + + @override + Future dispose() async { + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } + @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - logger.t('Switches loadSuccess'); - - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Center( - child: CircularProgressIndicatorAtom(), - ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> tempDevicesByRooms = - >{}; - - /// Go on all the devices and find only the devices that exist - /// in this room - final String roomId = roomEntity.uniqueId.getOrCrash(); - for (final DeviceEntityAbstract? deviceEntityAbstract - in state.devices.iter) { - if (deviceEntityAbstract == null) { - continue; - } - final int indexOfDeviceInRoom = - roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { - return element == deviceEntityAbstract.uniqueId.getOrCrash(); - }); - if (indexOfDeviceInRoom != -1) { - if (tempDevicesByRooms[roomId] == null) { - tempDevicesByRooms[roomId] = [deviceEntityAbstract]; - } else { - tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); - } - } - } - final List> devicesByRooms = []; - - tempDevicesByRooms.forEach((k, v) { - devicesByRooms.add(v.toImmutableList()); - }); - - return Container( - margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), - child: ListView.builder( - reverse: true, - padding: EdgeInsets.zero, - itemBuilder: (context, index) { - final List gradiantColor = roomColorGradiant; - - final devicesInRoom = devicesByRooms[index]; - - return RoomSwitches( - devicesInRoom, - gradiantColor, - roomEntity.cbjEntityName.getOrCrash(), - maxSwitchesToShow: 50, - ); - }, - itemCount: devicesByRooms.length, - ), - ); - } else { - return SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: TextAtom( - 'Switches does not exist.', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ), - ], + if (devices.isEmpty()) { + return SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: TextAtom( + 'Switches does not exist.', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ); - } - }, - loadFailure: (state) { - return CriticalSwitchFailureDisplay( - failure: state.devicesFailure, - ); - }, - switchesError: (SwitchesError value) { - return const TextAtom('Error'); - }, - ); - }, + ), + ), + ], + ), + ); + } + + final Map> tempDevicesByRooms = + >{}; + + /// Go on all the devices and find only the devices that exist + /// in this room + final String roomId = widget.roomEntity.uniqueId.getOrCrash(); + for (final DeviceEntityAbstract? deviceEntityAbstract in devices.iter) { + if (deviceEntityAbstract == null) { + continue; + } + final int indexOfDeviceInRoom = + widget.roomEntity.roomDevicesId.getOrCrash().indexWhere((element) { + return element == deviceEntityAbstract.uniqueId.getOrCrash(); + }); + if (indexOfDeviceInRoom != -1) { + if (tempDevicesByRooms[roomId] == null) { + tempDevicesByRooms[roomId] = [deviceEntityAbstract]; + } else { + tempDevicesByRooms[roomId]!.add(deviceEntityAbstract); + } + } + } + final List> devicesByRooms = []; + + tempDevicesByRooms.forEach((k, v) { + devicesByRooms.add(v.toImmutableList()); + }); + + return Container( + margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 15), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final List gradiantColor = widget.roomColorGradiant; + + final devicesInRoom = devicesByRooms[index]; + + return RoomSwitches( + devicesInRoom, + gradiantColor, + widget.roomEntity.cbjEntityName.getOrCrash(), + maxSwitchesToShow: 50, + ); + }, + itemCount: devicesByRooms.length, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart index 06d32b442..d2b9efe2e 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart @@ -1,22 +1,49 @@ +import 'dart:async'; + import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/application/switch_toggle/switch_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; /// Show switch toggles in a container with the background color from smart room /// object -class SwitchWidget extends StatelessWidget { +class SwitchWidget extends StatefulWidget { const SwitchWidget(this._deviceEntity); - final GenericSwitchDE? _deviceEntity; + final GenericSwitchDE _deviceEntity; + + @override + State createState() => _SwitchWidgetState(); +} + +class _SwitchWidgetState extends State { + int sendNewColorEachMilliseconds = 200; + Timer? timeFromLastColorChange; + HSVColor? lastColoredPicked; + + Future _changeAction(bool changeToState) async { + if (changeToState) { + await IDeviceRepository.instance.turnOnDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } else { + await IDeviceRepository.instance.turnOffDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } + } - void _onChange(BuildContext context, bool value) { - context.read().add( - SwitchToggleEvent.changeAction(_deviceEntity!, value), - ); + /// This function will make sure that the app sends color once each x seconds. + /// Moving the hand on the color slider sends tons of requests with + /// different colors which is not efficient and some device can't even handle + /// so many requests. + Future changeColorOncePerTimer() async { + await IDeviceRepository.instance.changeHsvColorDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + hsvColorToChange: lastColoredPicked!, + ); } @override @@ -24,8 +51,8 @@ class SwitchWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity!.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity!.switchState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.switchState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -41,44 +68,35 @@ class SwitchWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.0655, - toggleSize: screenSize.height * 0.0655, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: Icon( - MdiIcons.lightSwitch, - color: Colors.white, - ), - inactiveIcon: Icon( - MdiIcons.lightSwitch, - color: Colors.white70, - ), - onToggle: (bool value) => _onChange(context, value) - // _onChange(context, value), - - , + return Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.0655, + toggleSize: screenSize.height * 0.0655, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: Icon( + MdiIcons.lightSwitch, + color: Colors.white, + ), + inactiveIcon: Icon( + MdiIcons.lightSwitch, + color: Colors.white70, ), - ); - }, + onToggle: (bool value) => _changeAction(value)), ); } } diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart index 665868790..d763af4c0 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart @@ -1,18 +1,18 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class BlindsInTheRoom extends StatelessWidget { +class BlindsInTheRoom extends StatefulWidget { const BlindsInTheRoom({ required this.roomEntity, this.blindsInRoom, @@ -22,7 +22,7 @@ class BlindsInTheRoom extends StatelessWidget { factory BlindsInTheRoom.withAbstractDevice({ required RoomEntity roomEntity, required List tempDeviceInRoom, - required ListOfColors temprRoomColorGradiant, + required ListOfColors tempRoomColorGradiant, }) { final List tempLightsInRoom = []; @@ -33,7 +33,7 @@ class BlindsInTheRoom extends StatelessWidget { return BlindsInTheRoom( roomEntity: roomEntity, blindsInRoom: tempLightsInRoom, - roomColorGradiant: temprRoomColorGradiant, + roomColorGradiant: tempRoomColorGradiant, ); } @@ -41,21 +41,54 @@ class BlindsInTheRoom extends StatelessWidget { final List? blindsInRoom; final ListOfColors? roomColorGradiant; + @override + State createState() => _BlindsInTheRoomState(); +} + +class _BlindsInTheRoomState extends State { + Future _moveUpAllBlinds(List blindsIdToTurnUp) async { + FlushbarHelper.createLoading( + message: 'Pulling_Up_all_blinds'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.moveUpStateDevices(devicesId: blindsIdToTurnUp); + } + + Future _moveDownAllBlinds(List blindsIdToTurnDown) async { + FlushbarHelper.createLoading( + message: 'Pulling_down_all_blinds'.tr(), + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance + .moveDownStateDevices(devicesId: blindsIdToTurnDown); + } + + List extractDevicesId() { + final List devicesIdList = []; + for (final element in widget.blindsInRoom!) { + devicesIdList.add(element!.uniqueId.getOrCrash()); + } + return devicesIdList; + } + @override Widget build(BuildContext context) { String deviceText; - if (blindsInRoom!.length == 1) { - deviceText = blindsInRoom![0]!.cbjEntityName.getOrCrash()!; + if (widget.blindsInRoom!.length == 1) { + deviceText = widget.blindsInRoom![0]!.cbjEntityName.getOrCrash()!; } else { - deviceText = '_Blinds'.tr(args: [roomEntity.cbjEntityName.getOrCrash()]); + deviceText = + '_Blinds'.tr(args: [widget.roomEntity.cbjEntityName.getOrCrash()]); } return GestureDetector( onTap: () { context.router.push( RoomsBlindsRoute( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant, + roomEntity: widget.roomEntity, + roomColorGradiant: widget.roomColorGradiant, ), ); }, @@ -88,7 +121,7 @@ class BlindsInTheRoom extends StatelessWidget { ], ), ), - if (blindsInRoom!.length > 1) + if (widget.blindsInRoom!.length > 1) Expanded( child: Container( height: 55, @@ -106,7 +139,7 @@ class BlindsInTheRoom extends StatelessWidget { borderRadius: BorderRadius.circular(10), ), child: TextAtom( - blindsInRoom!.length.toString(), + widget.blindsInRoom!.length.toString(), textAlign: TextAlign.center, style: TextStyle( fontSize: 13, @@ -145,84 +178,61 @@ class BlindsInTheRoom extends StatelessWidget { const SizedBox( height: 10, ), - BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - padding: MaterialStateProperty.all( - EdgeInsets.zero, - ), - ), - onPressed: () { - context.read().add( - BlindsActorEvent.moveDownAllBlinds( - extractDevicesId(), - context, - ), - ); - }, - child: FaIcon( - FontAwesomeIcons.chevronDown, - color: Theme.of(context).textTheme.bodyMedium!.color, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), ), - TextAtom( - '·', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - padding: MaterialStateProperty.all( - EdgeInsets.zero, - ), - ), - onPressed: () { - context.read().add( - BlindsActorEvent.moveUpAllBlinds( - extractDevicesId(), - context, - ), - ); - }, - child: FaIcon( - FontAwesomeIcons.chevronUp, - color: Theme.of(context).textTheme.bodyMedium!.color, - ), + padding: MaterialStateProperty.all( + EdgeInsets.zero, + ), + ), + onPressed: () { + _moveDownAllBlinds(extractDevicesId()); + }, + child: FaIcon( + FontAwesomeIcons.chevronDown, + color: Theme.of(context).textTheme.bodyMedium!.color, + ), + ), + TextAtom( + '·', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), + ), + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), ), - ], - ); - }, + padding: MaterialStateProperty.all( + EdgeInsets.zero, + ), + ), + onPressed: () { + _moveUpAllBlinds(extractDevicesId()); + }, + child: FaIcon( + FontAwesomeIcons.chevronUp, + color: Theme.of(context).textTheme.bodyMedium!.color, + ), + ), + ], ), ], ), ), ); } - - List extractDevicesId() { - final List devicesIdList = []; - for (final element in blindsInRoom!) { - devicesIdList.add(element!.uniqueId.getOrCrash()); - } - return devicesIdList; - } } diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart index 49843497c..23493fc80 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/lights_in_the_room_block.dart @@ -1,3 +1,4 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; @@ -6,17 +7,16 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/application/lights/lights_actor/lights_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class LightsInTheRoomBlock extends StatelessWidget { +class LightsInTheRoomBlock extends StatefulWidget { const LightsInTheRoomBlock({ required this.roomEntity, required this.lightsInRoom, @@ -63,35 +63,75 @@ class LightsInTheRoomBlock extends StatelessWidget { final List rgbwLightsInRoom; final ListOfColors roomColorGradiant; + @override + State createState() => _LightsInTheRoomBlockState(); +} + +class _LightsInTheRoomBlockState extends State { + Future _turnOffAllLights(List lightsIdToTurnOff) async { + FlushbarHelper.createLoading( + message: 'Turning Off all lights', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOffDevices(devicesId: lightsIdToTurnOff); + } + + Future _turnOnAllLights(List lightsIdToTurnOn) async { + FlushbarHelper.createLoading( + message: 'Turning On all lights', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOnDevices(devicesId: lightsIdToTurnOn); + } + + List extractDevicesId() { + final List devicesIdList = []; + for (final element in widget.lightsInRoom) { + devicesIdList.add(element.uniqueId.getOrCrash()); + } + for (final element in widget.dimmableLightsInRoom) { + devicesIdList.add(element.uniqueId.getOrCrash()); + } + for (final element in widget.rgbwLightsInRoom) { + devicesIdList.add(element.uniqueId.getOrCrash()); + } + + return devicesIdList; + } + @override Widget build(BuildContext context) { String deviceText; - final int totalLightsInTheRoom = lightsInRoom.length + - dimmableLightsInRoom.length + - rgbwLightsInRoom.length; + final int totalLightsInTheRoom = widget.lightsInRoom.length + + widget.dimmableLightsInRoom.length + + widget.rgbwLightsInRoom.length; if (totalLightsInTheRoom == 1) { - if (lightsInRoom.isNotEmpty) { - deviceText = lightsInRoom.first.cbjEntityName.getOrCrash()!; - } else if (dimmableLightsInRoom.isNotEmpty) { - deviceText = dimmableLightsInRoom.first.cbjEntityName.getOrCrash()!; - } else if (rgbwLightsInRoom.isNotEmpty) { - deviceText = rgbwLightsInRoom.first.cbjEntityName.getOrCrash()!; + if (widget.lightsInRoom.isNotEmpty) { + deviceText = widget.lightsInRoom.first.cbjEntityName.getOrCrash()!; + } else if (widget.dimmableLightsInRoom.isNotEmpty) { + deviceText = + widget.dimmableLightsInRoom.first.cbjEntityName.getOrCrash()!; + } else if (widget.rgbwLightsInRoom.isNotEmpty) { + deviceText = widget.rgbwLightsInRoom.first.cbjEntityName.getOrCrash()!; } else { logger.w('Missing a line here'); deviceText = 'Light'; } } else { - deviceText = '_Lights'.tr(args: [roomEntity.cbjEntityName.getOrCrash()]); + deviceText = + '_Lights'.tr(args: [widget.roomEntity.cbjEntityName.getOrCrash()]); } return GestureDetector( onTap: () { context.router.push( RoomsLightsRoute( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant, + roomEntity: widget.roomEntity, + roomColorGradiant: widget.roomColorGradiant, ), ); }, @@ -181,89 +221,61 @@ class LightsInTheRoomBlock extends StatelessWidget { const SizedBox( height: 10, ), - BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - LightsActorEvent.turnOffAllLights( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'Off', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - TextAtom( - '·', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - LightsActorEvent.turnOnAllLights( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'On', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - ], - ); - }, + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOffAllLights(extractDevicesId()); + }, + child: TextAtom( + 'Off', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + TextAtom( + '·', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), + ), + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOnAllLights(extractDevicesId()); + }, + child: TextAtom( + 'On', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ], ), ], ), ), ); } - - List extractDevicesId() { - final List devicesIdList = []; - for (final element in lightsInRoom) { - devicesIdList.add(element.uniqueId.getOrCrash()); - } - for (final element in dimmableLightsInRoom) { - devicesIdList.add(element.uniqueId.getOrCrash()); - } - for (final element in rgbwLightsInRoom) { - devicesIdList.add(element.uniqueId.getOrCrash()); - } - - return devicesIdList; - } } diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart index 9734f2268..f50f5aa2e 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/smart_plug_in_the_room_block.dart @@ -1,18 +1,18 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; -import 'package:cybear_jinni/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; -class SmartPlugsInTheRoomBlock extends StatelessWidget { +class SmartPlugsInTheRoomBlock extends StatefulWidget { const SmartPlugsInTheRoomBlock({ required this.roomEntity, required this.smartPlugsInRoom, @@ -41,22 +41,46 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { final List smartPlugsInRoom; final ListOfColors roomColorGradiant; + @override + State createState() => + _SmartPlugsInTheRoomBlockState(); +} + +class _SmartPlugsInTheRoomBlockState extends State { + Future _turnOffAllSmartPlugs(List smartPlugsIdToTurnOff) async { + FlushbarHelper.createLoading( + message: 'Turning Off all smartPlugs', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOffDevices(devicesId: smartPlugsIdToTurnOff); + } + + Future _turnOnAllSmartPlugs(List smartPlugsIdToTurnOn) async { + FlushbarHelper.createLoading( + message: 'Turning On all smartPlugs', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOnDevices(devicesId: smartPlugsIdToTurnOn); + } + @override Widget build(BuildContext context) { String deviceText; - if (smartPlugsInRoom.length == 1) { - deviceText = smartPlugsInRoom[0].cbjEntityName.getOrCrash()!; + if (widget.smartPlugsInRoom.length == 1) { + deviceText = widget.smartPlugsInRoom[0].cbjEntityName.getOrCrash()!; } else { - deviceText = - '_SmartPlugs'.tr(args: [roomEntity.cbjEntityName.getOrCrash()]); + deviceText = '_SmartPlugs' + .tr(args: [widget.roomEntity.cbjEntityName.getOrCrash()]); } return GestureDetector( onTap: () { context.router.push( RoomsSmartPlugsRoute( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant, + roomEntity: widget.roomEntity, + roomColorGradiant: widget.roomColorGradiant, ), ); }, @@ -89,7 +113,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { ], ), ), - if (smartPlugsInRoom.length > 1) + if (widget.smartPlugsInRoom.length > 1) Expanded( child: Container( height: 55, @@ -107,7 +131,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { borderRadius: BorderRadius.circular(10), ), child: TextAtom( - smartPlugsInRoom.length.toString(), + widget.smartPlugsInRoom.length.toString(), textAlign: TextAlign.center, style: TextStyle( fontSize: 13, @@ -146,70 +170,57 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { const SizedBox( height: 10, ), - BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - SmartPlugsActorEvent.turnOffAllSmartPlugs( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'Off', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - TextAtom( - '·', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - SmartPlugsActorEvent.turnOnAllSmartPlugs( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'On', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - ], - ); - }, + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOffAllSmartPlugs(extractDevicesId()); + }, + child: TextAtom( + 'Off', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + TextAtom( + '·', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), + ), + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOnAllSmartPlugs(extractDevicesId()); + }, + child: TextAtom( + 'On', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ], ), ], ), @@ -219,7 +230,7 @@ class SmartPlugsInTheRoomBlock extends StatelessWidget { List extractDevicesId() { final List devicesIdList = []; - for (final element in smartPlugsInRoom) { + for (final element in widget.smartPlugsInRoom) { devicesIdList.add(element.uniqueId.getOrCrash()); } return devicesIdList; diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart index ce5028235..acb94bd99 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart @@ -1,15 +1,15 @@ +import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.dart'; -import 'package:cybear_jinni/application/switches/switches_actor/switches_actor_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; class SwitchesInTheRoomBlock extends StatelessWidget { @@ -41,6 +41,26 @@ class SwitchesInTheRoomBlock extends StatelessWidget { final List switchesInRoom; final ListOfColors roomColorGradiant; + Future _turnOffAllSwitches( + BuildContext context, List? switchesIdToTurnOff) async { + FlushbarHelper.createLoading( + message: 'Turning Off all switches', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOffDevices(devicesId: switchesIdToTurnOff); + } + + Future _turnOnAllSwitches( + BuildContext context, List? switchesIdToTurnOn) async { + FlushbarHelper.createLoading( + message: 'Turning On all switches', + linearProgressIndicator: const LinearProgressIndicator(), + ).show(context); + + IDeviceRepository.instance.turnOnDevices(devicesId: switchesIdToTurnOn); + } + @override Widget build(BuildContext context) { String deviceText; @@ -146,70 +166,63 @@ class SwitchesInTheRoomBlock extends StatelessWidget { const SizedBox( height: 10, ), - BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - SwitchesActorEvent.turnOffAllSwitches( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'Off', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - TextAtom( - '·', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.grey.withOpacity(0.6), - ), - side: MaterialStateProperty.all( - const BorderSide(width: 0.2), - ), - ), - onPressed: () { - context.read().add( - SwitchesActorEvent.turnOnAllSwitches( - extractDevicesId(), - context, - ), - ); - }, - child: TextAtom( - 'On', - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), ), - ], - ); - }, + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOffAllSwitches( + context, + extractDevicesId(), + ); + }, + child: TextAtom( + 'Off', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + TextAtom( + '·', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.grey.withOpacity(0.6), + ), + side: MaterialStateProperty.all( + const BorderSide(width: 0.2), + ), + ), + onPressed: () { + _turnOnAllSwitches( + context, + extractDevicesId(), + ); + }, + child: TextAtom( + 'On', + style: TextStyle( + fontSize: 14, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), + ), + ], ), ], ), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart index 65bce1560..6714e3154 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rom_widget.dart @@ -2,15 +2,6 @@ import 'package:another_flushbar/flushbar_helper.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/blinds/blinds_actor/blinds_actor_bloc.dart'; -import 'package:cybear_jinni/application/lights/lights_actor/lights_actor_bloc.dart'; -import 'package:cybear_jinni/application/printers/printers_actor/printers_actor_bloc.dart'; -import 'package:cybear_jinni/application/security_camera/security_camera_actor/security_camera_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_computers/smart_computers_actor/smart_computers_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_plugs/smart_plugs_actor/smart_plugs_actor_bloc.dart'; -import 'package:cybear_jinni/application/smart_tv/smart_tv_actor/smart_tv_actor_bloc.dart'; -import 'package:cybear_jinni/application/switches/switches_actor/switches_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/blinds_in_the_room.dart'; @@ -24,10 +15,9 @@ import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class RoomWidget extends StatelessWidget { +class RoomWidget extends StatefulWidget { const RoomWidget({ required this.roomColorGradiant, required this.roomsList, @@ -53,24 +43,29 @@ class RoomWidget extends StatelessWidget { final int numberOfDevicesInTheRoom; final RoomEntity roomEntity; + @override + State createState() => _RoomWidgetState(); +} + +class _RoomWidgetState extends State { @override Widget build(BuildContext context) { bool didAddedLights = false; return Container( margin: EdgeInsets.only( - bottom: bottomMargin, - left: leftMargin, - right: rightMargin, + bottom: widget.bottomMargin, + left: widget.leftMargin, + right: widget.rightMargin, ), decoration: BoxDecoration( gradient: LinearGradient( - colors: roomColorGradiant.listOfColors!, + colors: widget.roomColorGradiant.listOfColors!, begin: Alignment.bottomLeft, end: Alignment.topLeft, ), color: Colors.white, - borderRadius: BorderRadius.circular(borderRadius), + borderRadius: BorderRadius.circular(widget.borderRadius), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.6), @@ -89,7 +84,7 @@ class RoomWidget extends StatelessWidget { margin: const EdgeInsets.all(3), decoration: BoxDecoration( color: Colors.black.withOpacity(0.07), - borderRadius: BorderRadius.circular(borderRadius), + borderRadius: BorderRadius.circular(widget.borderRadius), ), child: Column( children: [ @@ -99,10 +94,10 @@ class RoomWidget extends StatelessWidget { child: Stack( children: [ TextAtom( - roomsList + widget.roomsList .firstWhere( (element) => - element!.uniqueId.getOrCrash() == roomId, + element!.uniqueId.getOrCrash() == widget.roomId, )! .cbjEntityName .getOrCrash(), @@ -115,10 +110,10 @@ class RoomWidget extends StatelessWidget { ), ), TextAtom( - roomsList + widget.roomsList .firstWhere( (element) => - element!.uniqueId.getOrCrash() == roomId, + element!.uniqueId.getOrCrash() == widget.roomId, )! .cbjEntityName .getOrCrash(), @@ -130,17 +125,17 @@ class RoomWidget extends StatelessWidget { ], ), ), - if (numberOfDevicesInTheRoom == 1) + if (widget.numberOfDevicesInTheRoom == 1) TextAtom( '_device', style: const TextStyle(fontSize: 12), - translationArgs: [numberOfDevicesInTheRoom.toString()], + translationArgs: [widget.numberOfDevicesInTheRoom.toString()], ) else TextAtom( '_devices', style: const TextStyle(fontSize: 12), - translationArgs: [numberOfDevicesInTheRoom.toString()], + translationArgs: [widget.numberOfDevicesInTheRoom.toString()], ), /// Build the devices in the room by type @@ -154,14 +149,15 @@ class RoomWidget extends StatelessWidget { crossAxisSpacing: 10, mainAxisSpacing: 15, ), - itemCount: tempDevicesByRoomsByType[roomId]!.keys.length, + itemCount: + widget.tempDevicesByRoomsByType[widget.roomId]!.keys.length, itemBuilder: (BuildContext ctx, secondIndex) { - final String deviceType = tempDevicesByRoomsByType[roomId]! - .keys + final String deviceType = widget + .tempDevicesByRoomsByType[widget.roomId]!.keys .elementAt(secondIndex); - List devicesInTheRoom = - tempDevicesByRoomsByType[roomId]![deviceType]!; + List devicesInTheRoom = widget + .tempDevicesByRoomsByType[widget.roomId]![deviceType]!; if (deviceType == EntityTypes.light.toString() || deviceType == EntityTypes.dimmableLight.toString() || @@ -175,116 +171,94 @@ class RoomWidget extends StatelessWidget { final List? tempLightDevicesInTheRoom = - tempDevicesByRoomsByType[roomId] + widget.tempDevicesByRoomsByType[widget.roomId] ?[EntityTypes.light.toString()]; devicesInTheRoom.addAll(tempLightDevicesInTheRoom ?? []); final List? tempDimmableLightDevicesInTheRoom = - tempDevicesByRoomsByType[roomId] + widget.tempDevicesByRoomsByType[widget.roomId] ?[EntityTypes.dimmableLight.toString()]; devicesInTheRoom .addAll(tempDimmableLightDevicesInTheRoom ?? []); final List? tempRgbwLightDevicesInTheRoom = - tempDevicesByRoomsByType[roomId] + widget.tempDevicesByRoomsByType[widget.roomId] ?[EntityTypes.rgbwLights.toString()]; devicesInTheRoom .addAll(tempRgbwLightDevicesInTheRoom ?? []); - return BlocProvider( - create: (context) => getIt(), - child: LightsInTheRoomBlock.withAbstractDevice( - roomEntity: roomEntity, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return LightsInTheRoomBlock.withAbstractDevice( + roomEntity: widget.roomEntity, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.switch_.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: SwitchesInTheRoomBlock.withAbstractDevice( - roomEntityTemp: roomsList.firstWhere( - (element) => element!.uniqueId.getOrCrash() == roomId, - )!, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return SwitchesInTheRoomBlock.withAbstractDevice( + roomEntityTemp: widget.roomsList.firstWhere( + (element) => + element!.uniqueId.getOrCrash() == widget.roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.blinds.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: BlindsInTheRoom.withAbstractDevice( - roomEntity: roomEntity, - tempDeviceInRoom: devicesInTheRoom, - temprRoomColorGradiant: roomColorGradiant, - ), + return BlindsInTheRoom.withAbstractDevice( + roomEntity: widget.roomEntity, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.boiler.toString()) { //TODO: Boiler should not user Blinds block - return BlocProvider( - create: (context) => getIt(), - child: BoilersInTheRoom.withAbstractDevice( - roomEntity: roomEntity, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return BoilersInTheRoom.withAbstractDevice( + roomEntity: widget.roomEntity, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.smartTV.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: SmartTvInTheRoom.withAbstractDevice( - roomEntity: roomEntity, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return SmartTvInTheRoom.withAbstractDevice( + roomEntity: widget.roomEntity, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.smartPlug.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: SmartPlugsInTheRoomBlock.withAbstractDevice( - roomEntityTemp: roomsList.firstWhere( - (element) => element!.uniqueId.getOrCrash() == roomId, - )!, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return SmartPlugsInTheRoomBlock.withAbstractDevice( + roomEntityTemp: widget.roomsList.firstWhere( + (element) => + element!.uniqueId.getOrCrash() == widget.roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.smartComputer.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: SmartComputersInTheRoomBlock.withAbstractDevice( - roomEntityTemp: roomsList.firstWhere( - (element) => element!.uniqueId.getOrCrash() == roomId, - )!, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return SmartComputersInTheRoomBlock.withAbstractDevice( + roomEntityTemp: widget.roomsList.firstWhere( + (element) => + element!.uniqueId.getOrCrash() == widget.roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.printer.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: PrintersInTheRoomBlock.withAbstractDevice( - roomEntityTemp: roomsList.firstWhere( - (element) => element!.uniqueId.getOrCrash() == roomId, - )!, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return PrintersInTheRoomBlock.withAbstractDevice( + roomEntityTemp: widget.roomsList.firstWhere( + (element) => + element!.uniqueId.getOrCrash() == widget.roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } else if (deviceType == EntityTypes.securityCamera.toString()) { - return BlocProvider( - create: (context) => getIt(), - child: SecurityCamerasInTheRoomBlock.withAbstractDevice( - roomEntityTemp: roomsList.firstWhere( - (element) => element!.uniqueId.getOrCrash() == roomId, - )!, - tempDeviceInRoom: devicesInTheRoom, - tempRoomColorGradiant: roomColorGradiant, - ), + return SecurityCamerasInTheRoomBlock.withAbstractDevice( + roomEntityTemp: widget.roomsList.firstWhere( + (element) => + element!.uniqueId.getOrCrash() == widget.roomId, + )!, + tempDeviceInRoom: devicesInTheRoom, + tempRoomColorGradiant: widget.roomColorGradiant, ); } diff --git a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart index 28492a0d3..8a6ae674f 100644 --- a/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart +++ b/lib/presentation/pages/scenes/widgets/folder_of_scenes.dart @@ -2,13 +2,10 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_failures.dart'; -import 'package:cybear_jinni/application/scene/scene_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/scenes/widgets/scene_widget.dart'; import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; class FolderOfScenesWidget extends StatefulWidget { const FolderOfScenesWidget({required this.folderOfScenes}); @@ -25,6 +22,8 @@ class _FolderOfScenesWidgetState extends State { List allScenesInTheRoom = []; List? scenesList; + late SceneCbjEntity sceneCbj; + @override void initState() { super.initState(); @@ -83,15 +82,7 @@ class _FolderOfScenesWidgetState extends State { reverse: true, itemBuilder: (context, index) { final SceneCbjEntity sceneCbj = scenesList![index]; - return BlocProvider( - create: (context) => getIt() - ..add( - SceneEvent.initialized( - sceneCbj: sceneCbj, - ), - ), - child: SceneWidget(sceneCbj), - ); + return SceneWidget(sceneCbj); }, itemCount: scenesList!.length, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( diff --git a/lib/presentation/pages/scenes/widgets/scene_widget.dart b/lib/presentation/pages/scenes/widgets/scene_widget.dart index 0133ae3b1..5a9fb2d70 100644 --- a/lib/presentation/pages/scenes/widgets/scene_widget.dart +++ b/lib/presentation/pages/scenes/widgets/scene_widget.dart @@ -1,95 +1,74 @@ -import 'package:another_flushbar/flushbar_helper.dart'; +import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; -import 'package:cybear_jinni/application/scene/scene_bloc.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:kt_dart/collection.dart'; -class SceneWidget extends StatelessWidget { +class SceneWidget extends StatefulWidget { const SceneWidget(this.currentScene); final SceneCbjEntity currentScene; @override - Widget build(BuildContext context) { - return BlocConsumer( - listener: (context, SceneState state) { - state.map( - (value) => (v) {}, - loading: (loadingNow) {}, - error: (errorNow) { - FlushbarHelper.createError(message: 'Error'); - }, - loaded: (_) => const TextAtom('loaded'), - ); - }, - builder: (context, state) { - return state.map( - (value) => const TextAtom('value'), - loading: (_) => const TextAtom('Loading'), - loaded: (sceneState) { - return Container( - margin: const EdgeInsets.fromLTRB(5, 0, 5, 10), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color( - int.parse(currentScene.backgroundColor.getOrCrash()), - ), - padding: const EdgeInsets.fromLTRB(5, 5, 5, 5), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(30), - side: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - width: 0.6, - ), - ), - ), - onPressed: () { - HapticFeedback.lightImpact(); + State createState() => _SceneWidgetState(); +} + +class _SceneWidgetState extends State { + late SceneCbjEntity sceneCbj; - Fluttertoast.showToast( - msg: 'Activating Scene', - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.BOTTOM, - backgroundColor: Colors.purple, - textColor: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); + Future _activateScene() async { + ISceneCbjRepository.instance.activateScenes([sceneCbj].toImmutableList()); + } - context - .read() - .add(const SceneEvent.activateScene()); + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.fromLTRB(5, 0, 5, 10), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Color( + int.parse(widget.currentScene.backgroundColor.getOrCrash()), + ), + padding: const EdgeInsets.fromLTRB(5, 5, 5, 5), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30), + side: BorderSide( + color: Theme.of(context).textTheme.bodyLarge!.color!, + width: 0.6, + ), + ), + ), + onPressed: () { + HapticFeedback.lightImpact(); - // smartDevicesWithWish - // .forEach((SmartDeviceObject key, List value) { - // for (final EntityActions deviceActionForSmartDevice in value) { - // key.executeWish(wishEnumForSmartDevice); - // } - // }); - }, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(30), - color: Colors.black54, - ), - alignment: Alignment.center, - child: TextAtom( - currentScene.name.getOrCrash(), - style: TextStyle( - fontSize: 23, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - textAlign: TextAlign.center, - ), - ), - ), - ); - }, - error: (_) => const TextAtom('Error'), - ); - }, + Fluttertoast.showToast( + msg: 'Activating Scene', + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.purple, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + _activateScene(); + }, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(30), + color: Colors.black54, + ), + alignment: Alignment.center, + child: TextAtom( + widget.currentScene.name.getOrCrash(), + style: TextStyle( + fontSize: 23, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + textAlign: TextAlign.center, + ), + ), + ), ); } } From 257a396526dcc05bbdba3fbf4d08a1ec56a1e45d Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 22:48:22 +0200 Subject: [PATCH 14/15] Removed all use of block and application directory --- .../device_actor/device_actor_bloc.dart | 29 -- .../device_actor/device_actor_event.dart | 8 - .../device_actor/device_actor_state.dart | 13 - .../device_watcher/device_watcher_bloc.dart | 148 -------- .../device_watcher/device_watcher_event.dart | 14 - .../device_watcher/device_watcher_state.dart | 18 - .../light_toggle/light_toggle_bloc.dart | 101 ------ .../light_toggle/light_toggle_event.dart | 28 -- .../light_toggle/light_toggle_state.dart | 16 - lib/infrastructure/phone_hub/phone_hub.dart | 4 + .../core/devices_cards/light_card.dart | 89 +++-- .../add_scene/add_scene_page.dart | 2 +- .../configure_new_cbj_comp_widget.dart | 18 +- .../widgets/cbj_comp_card.dart | 18 +- .../cbj_comp_card_with_devices_controll.dart | 128 +++---- .../blinds/rooms_blinds_page.dart | 86 ++--- .../blinds/widgets/rooms_blinds_widget.dart | 2 +- .../boilers/rooms_boilers_page.dart | 86 ++--- .../boilers/widgets/boilers_widget.dart | 51 +-- .../boilers/widgets/room_boilers.dart | 7 +- .../boilers/widgets/rooms_boilers_widget.dart | 5 +- .../lights/rooms_lights_page.dart | 82 ++--- .../lights_widgets/dimmable_light_widget.dart | 210 ++++++------ .../widgets/lights_widgets/light_widget.dart | 94 +++--- .../rgb_light_widgets/light_color_mods.dart | 99 ++++-- .../rgb_light_widgets/rgbw_light_widget.dart | 243 +++++++------ .../lights/widgets/room_lights.dart | 22 +- .../printers/rooms_printers_page.dart | 84 ++--- .../rooms_smart_computers_page.dart | 84 ++--- .../smart_plugs/rooms_smart_plugs_page.dart | 84 ++--- .../widgets/rooms_smart_plugs_widget.dart | 5 +- .../smart_tv/rooms_smart_tvs_page.dart | 84 ++--- .../switches/rooms_switches_page.dart | 84 ++--- .../switches/widgets/switches_widget.dart | 51 +-- .../switches_in_the_room_block.dart | 8 +- .../smart_devices_by_rooms.dart | 319 +++++++++++------- .../smart_devices_widgets.dart | 67 +--- pubspec.yaml | 2 - 38 files changed, 928 insertions(+), 1565 deletions(-) delete mode 100644 lib/application/devices/device_actor/device_actor_bloc.dart delete mode 100644 lib/application/devices/device_actor/device_actor_event.dart delete mode 100644 lib/application/devices/device_actor/device_actor_state.dart delete mode 100644 lib/application/devices/device_watcher/device_watcher_bloc.dart delete mode 100644 lib/application/devices/device_watcher/device_watcher_event.dart delete mode 100644 lib/application/devices/device_watcher/device_watcher_state.dart delete mode 100644 lib/application/light_toggle/light_toggle_bloc.dart delete mode 100644 lib/application/light_toggle/light_toggle_event.dart delete mode 100644 lib/application/light_toggle/light_toggle_state.dart diff --git a/lib/application/devices/device_actor/device_actor_bloc.dart b/lib/application/devices/device_actor/device_actor_bloc.dart deleted file mode 100644 index 53f38724d..000000000 --- a/lib/application/devices/device_actor/device_actor_bloc.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'device_actor_bloc.freezed.dart'; -part 'device_actor_event.dart'; -part 'device_actor_state.dart'; - -@injectable -class DeviceActorBloc extends Bloc { - DeviceActorBloc() : super(const DeviceActorState.initial()) { - on(_deleted); - on(_initialized); - } - - Future _deleted( - Deleted event, - Emitter emit, - ) async {} - - Future _initialized( - Initialized event, - Emitter emit, - ) async {} -} diff --git a/lib/application/devices/device_actor/device_actor_event.dart b/lib/application/devices/device_actor/device_actor_event.dart deleted file mode 100644 index 9e08e0a0a..000000000 --- a/lib/application/devices/device_actor/device_actor_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'device_actor_bloc.dart'; - -@freezed -class DeviceActorEvent with _$DeviceActorEvent { - const factory DeviceActorEvent.initialized() = Initialized; - - const factory DeviceActorEvent.deleted(GenericLightDE deviceEntity) = Deleted; -} diff --git a/lib/application/devices/device_actor/device_actor_state.dart b/lib/application/devices/device_actor/device_actor_state.dart deleted file mode 100644 index 4208749d8..000000000 --- a/lib/application/devices/device_actor/device_actor_state.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'device_actor_bloc.dart'; - -@freezed -class DeviceActorState with _$DeviceActorState { - const factory DeviceActorState.initial() = _Initial; - - const factory DeviceActorState.actionInProgress() = _ActionInProgress; - - const factory DeviceActorState.deleteFailure(DevicesFailure devicesFailure) = - _DeleteFailure; - - const factory DeviceActorState.deleteSuccess() = _DeleteSuccess; -} diff --git a/lib/application/devices/device_watcher/device_watcher_bloc.dart b/lib/application/devices/device_watcher/device_watcher_bloc.dart deleted file mode 100644 index 2255495c3..000000000 --- a/lib/application/devices/device_watcher/device_watcher_bloc.dart +++ /dev/null @@ -1,148 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; -import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/domain/device/devices_failures.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; -import 'package:dartz/dartz.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; -import 'package:kt_dart/kt.dart'; - -part 'device_watcher_bloc.freezed.dart'; -part 'device_watcher_event.dart'; -part 'device_watcher_state.dart'; - -@injectable -class DeviceWatcherBloc extends Bloc { - DeviceWatcherBloc() : super(DeviceWatcherState.initial()) { - on(_watchAllStarted); - on(_roomsReceived); - on(_devicesReceived); - } - - KtList listOfDevices = [null].toImmutableList(); - KtList listOfRooms = [null].toImmutableList(); - - StreamSubscription>>? - _roomStreamSubscription; - - StreamSubscription>>? - _deviceStreamSubscription; - late RoomEntity discoveredRoom; - // - // @override - // Stream mapEventToState( - // DeviceWatcherEvent event, - // ) async* { - - // devicesReceived: (e) async* { - - // }, - // ); - // } - - Future _roomsReceived( - RoomsReceived event, - Emitter emit, - ) async { - emit(const DeviceWatcherState.loadInProgress()); - - emit( - event.failureOrRooms.fold( - (f) => - const DeviceWatcherState.loadFailure(DevicesFailure.unexpected()), - (d) { - listOfRooms = d; - - return DeviceWatcherState.loadSuccess( - listOfRooms, - listOfDevices, - ); - }), - ); - } - - Future _devicesReceived( - DevicesReceived event, - Emitter emit, - ) async { - emit(const DeviceWatcherState.loadInProgress()); - - emit( - event.failureOrDevices.fold((f) => DeviceWatcherState.loadFailure(f), - (d) { - listOfDevices = d; - - return DeviceWatcherState.loadSuccess( - listOfRooms, - listOfDevices, - ); - }), - ); - } - - Future _watchAllStarted( - WatchAllStarted event, - Emitter emit, - ) async { - emit(const DeviceWatcherState.loadInProgress()); - - discoveredRoom = RoomEntity( - uniqueId: - RoomUniqueId.fromUniqueString('00000000-0000-0000-0000-000000000000'), - cbjEntityName: RoomDefaultName('Discovered'), - roomTypes: RoomTypes(const []), - roomDevicesId: RoomDevicesId(const []), - roomScenesId: RoomScenesId(const []), - roomRoutinesId: RoomRoutinesId(const []), - roomBindingsId: RoomBindingsId(const []), - roomMostUsedBy: RoomMostUsedBy(const []), - roomPermissions: RoomPermissions(const []), - background: RoomBackground( - 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', - ), - ); - - final Map allDevice = - await PhoneHub().getAllDevices; - - for (final String deviceId in allDevice.keys) { - discoveredRoom.addDeviceId(deviceId); - } - - add( - DeviceWatcherEvent.roomsReceived( - right([discoveredRoom].toImmutableList()), - ), - ); - - add( - DeviceWatcherEvent.devicesReceived( - right(allDevice.values.toImmutableList()), - ), - ); - - _roomStreamSubscription = - IRoomRepository.instance.watchAllRooms().listen((eventWatch) { - add(DeviceWatcherEvent.roomsReceived(eventWatch)); - }); - - _deviceStreamSubscription = - IDeviceRepository.instance.watchAllDevices().listen((eventWatch) { - add(DeviceWatcherEvent.devicesReceived(eventWatch)); - }); - } - - @override - Future close() async { - await _roomStreamSubscription?.cancel(); - await _deviceStreamSubscription?.cancel(); - return super.close(); - } -} diff --git a/lib/application/devices/device_watcher/device_watcher_event.dart b/lib/application/devices/device_watcher/device_watcher_event.dart deleted file mode 100644 index 5015140fb..000000000 --- a/lib/application/devices/device_watcher/device_watcher_event.dart +++ /dev/null @@ -1,14 +0,0 @@ -part of 'device_watcher_bloc.dart'; - -@freezed -class DeviceWatcherEvent with _$DeviceWatcherEvent { - const factory DeviceWatcherEvent.watchAllStarted() = WatchAllStarted; - - const factory DeviceWatcherEvent.roomsReceived( - Either> failureOrRooms, - ) = RoomsReceived; - - const factory DeviceWatcherEvent.devicesReceived( - Either> failureOrDevices, - ) = DevicesReceived; -} diff --git a/lib/application/devices/device_watcher/device_watcher_state.dart b/lib/application/devices/device_watcher/device_watcher_state.dart deleted file mode 100644 index 7b2ef5330..000000000 --- a/lib/application/devices/device_watcher/device_watcher_state.dart +++ /dev/null @@ -1,18 +0,0 @@ -part of 'device_watcher_bloc.dart'; - -@freezed -class DeviceWatcherState with _$DeviceWatcherState { - factory DeviceWatcherState.initial() = _Initial; - - const factory DeviceWatcherState.loadInProgress() = _LoadInProgress; - - const factory DeviceWatcherState.loadSuccess( - KtList rooms, - KtList devices, - ) = _LoadSuccess; - - const factory DeviceWatcherState.loadFailure(DevicesFailure devicesFailure) = - _loadFailure; - - const factory DeviceWatcherState.error() = Error; -} diff --git a/lib/application/light_toggle/light_toggle_bloc.dart b/lib/application/light_toggle/light_toggle_bloc.dart deleted file mode 100644 index 59ab61aea..000000000 --- a/lib/application/light_toggle/light_toggle_bloc.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/domain/device/i_device_repository.dart'; -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; - -part 'light_toggle_bloc.freezed.dart'; -part 'light_toggle_event.dart'; -part 'light_toggle_state.dart'; - -@injectable -class LightToggleBloc extends Bloc { - LightToggleBloc() : super(LightToggleState.initial()) { - on(_initialized); - on(_changeState); - on(_changeColorTemperature); - on(_changeHsvColor); - on(_changeBrightness); - } - - Future _initialized( - Initialized event, - Emitter emit, - ) async { - final GenericRgbwLightDE rgbwLightDe = event.rgbwLightDe; - - int lightColorTemperature = - int.parse(rgbwLightDe.lightColorTemperature.getOrCrash()); - - if (lightColorTemperature > 10000) { - lightColorTemperature = 10000; - } - - double lightBrightness = - double.parse(rgbwLightDe.lightBrightness.getOrCrash()); - - if (lightBrightness > 100) { - lightBrightness = 100; - } - - emit( - state.copyWith( - colorTemperature: lightColorTemperature, - brightness: lightBrightness, - ), - ); - } - - Future _changeState( - ChangeState event, - Emitter emit, - ) async { - if (event.changeToState) { - await IDeviceRepository.instance.turnOnDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } else { - await IDeviceRepository.instance.turnOffDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - ); - } - } - - Future _changeColorTemperature( - ChangeColorTemperature event, - Emitter emit, - ) async { - emit(state.copyWith(colorTemperature: event.newColorTemperature)); - IDeviceRepository.instance.changeColorTemperatureDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - colorTemperatureToChange: event.newColorTemperature, - ); - } - - Future _changeHsvColor( - ChangeHsvColor event, - Emitter emit, - ) async { - emit(state.copyWith(hsvColor: event.newHsvColor)); - IDeviceRepository.instance.changeHsvColorDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - hsvColorToChange: event.newHsvColor, - ); - } - - Future _changeBrightness( - ChangeBrightness event, - Emitter emit, - ) async { - emit(state.copyWith(brightness: event.brightness)); - - IDeviceRepository.instance.changeBrightnessDevices( - devicesId: [event.deviceEntity.uniqueId.getOrCrash()], - brightnessToChange: event.brightness.round(), - ); - } -} diff --git a/lib/application/light_toggle/light_toggle_event.dart b/lib/application/light_toggle/light_toggle_event.dart deleted file mode 100644 index 6a7346485..000000000 --- a/lib/application/light_toggle/light_toggle_event.dart +++ /dev/null @@ -1,28 +0,0 @@ -part of 'light_toggle_bloc.dart'; - -@freezed -class LightToggleEvent with _$LightToggleEvent { - const factory LightToggleEvent.initialized({ - required GenericRgbwLightDE rgbwLightDe, - }) = Initialized; - - const factory LightToggleEvent.changeAction({ - required DeviceEntityAbstract deviceEntity, - required bool changeToState, - }) = ChangeState; - - const factory LightToggleEvent.changeColorTemperature({ - required DeviceEntityAbstract deviceEntity, - required int newColorTemperature, - }) = ChangeColorTemperature; - - const factory LightToggleEvent.changeHsvColor({ - required DeviceEntityAbstract deviceEntity, - required HSVColor newHsvColor, - }) = ChangeHsvColor; - - const factory LightToggleEvent.changeBrightness({ - required DeviceEntityAbstract deviceEntity, - required double brightness, - }) = ChangeBrightness; -} diff --git a/lib/application/light_toggle/light_toggle_state.dart b/lib/application/light_toggle/light_toggle_state.dart deleted file mode 100644 index 059eacbef..000000000 --- a/lib/application/light_toggle/light_toggle_state.dart +++ /dev/null @@ -1,16 +0,0 @@ -part of 'light_toggle_bloc.dart'; - -@freezed -class LightToggleState with _$LightToggleState { - const factory LightToggleState({ - required int colorTemperature, - required HSVColor hsvColor, - required double brightness, - }) = _LightToggleState; - - factory LightToggleState.initial() => LightToggleState( - colorTemperature: 4500, - hsvColor: HSVColor.fromColor(Colors.white), - brightness: 100, - ); -} diff --git a/lib/infrastructure/phone_hub/phone_hub.dart b/lib/infrastructure/phone_hub/phone_hub.dart index 3e6f3405b..9fef37a96 100644 --- a/lib/infrastructure/phone_hub/phone_hub.dart +++ b/lib/infrastructure/phone_hub/phone_hub.dart @@ -60,7 +60,11 @@ class PhoneHub { } void startListen() { + if (phoneAsHub) { + return; + } phoneAsHub = true; + CompaniesConnectorConjector.updateAllDevicesReposWithDeviceChanges( AppRequestsToHub.appRequestsToHubStreamController.stream .map((clientStatusRequests) { diff --git a/lib/presentation/core/devices_cards/light_card.dart b/lib/presentation/core/devices_cards/light_card.dart index b5c591dde..faed28ae8 100644 --- a/lib/presentation/core/devices_cards/light_card.dart +++ b/lib/presentation/core/devices_cards/light_card.dart @@ -2,9 +2,8 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_value_objects.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -13,16 +12,20 @@ class LightCard extends StatelessWidget { final GenericLightDE? _deviceEntity; - void _onChange(BuildContext context, bool value) { + Future _onChange(bool value) async { final GenericLightDE tempDeviceEntity = _deviceEntity! ..entityStateGRPC = EntityState(EntityStateGRPC.waitingInCloud.toString()) ..lightSwitchState = GenericLightSwitchState(value.toString()); - context.read().add( - LightToggleEvent.changeAction( - deviceEntity: tempDeviceEntity, - changeToState: true, - ), - ); + + if (value) { + await IDeviceRepository.instance.turnOnDevices( + devicesId: [tempDeviceEntity.uniqueId.getOrCrash()], + ); + } else { + await IDeviceRepository.instance.turnOffDevices( + devicesId: [tempDeviceEntity.uniqueId.getOrCrash()], + ); + } } @override @@ -47,44 +50,36 @@ class LightCard extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Theme.of(context).primaryColor, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.solidLightbulb, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.lightbulb, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(context, value) - // _onChange(context, value), - - , - ), - ); - }, + return Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Theme.of(context).primaryColor, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.solidLightbulb, + color: Color(0xFFF8E3A1), + ), + inactiveIcon: Icon( + FontAwesomeIcons.lightbulb, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + onToggle: _onChange, + ), ); } } diff --git a/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart b/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart index 47e8bca24..7ebd5cf8d 100644 --- a/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart +++ b/lib/presentation/pages/add_new_automation_process/add_scene/add_scene_page.dart @@ -32,7 +32,7 @@ class AddScenePage extends StatelessWidget { leftIcon: FontAwesomeIcons.arrowLeft, leftIconFunction: backButtonFunction, ), - AddSceneWidget() + AddSceneWidget(), ], ), ), diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index 5ef81f477..a95ef01c3 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -3,7 +3,6 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/pr import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/utils.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart'; @@ -12,14 +11,12 @@ import 'package:cybear_jinni/domain/manage_network/i_manage_network_repository.d import 'package:cybear_jinni/domain/manage_network/manage_network_entity.dart'; import 'package:cybear_jinni/domain/security_bear/i_security_bear_connection_repository.dart'; import 'package:cybear_jinni/domain/security_bear/security_bear_failures.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/blinds_card.dart'; import 'package:cybear_jinni/presentation/core/devices_cards/light_card.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart'; @@ -180,10 +177,7 @@ class _ConfigureNewCbjCompWidgetsState TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Expanded( child: Center( - child: BlocProvider( - create: (context) => getIt(), - child: LightCard(device), - ), + child: LightCard(device), ), ), ], @@ -198,10 +192,7 @@ class _ConfigureNewCbjCompWidgetsState TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Expanded( child: Center( - child: BlocProvider( - create: (context) => getIt(), - child: LightCard(device), - ), + child: LightCard(device), ), ), ], @@ -213,10 +204,7 @@ class _ConfigureNewCbjCompWidgetsState children: [ TextAtom('Type: ${device.entityTypes.getOrCrash()}'), Center( - child: BlocProvider( - create: (context) => getIt(), - child: BlindsCard(device), - ), + child: BlindsCard(device), ), ], ), diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart index cf1c2d804..f71c42ab8 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card.dart @@ -1,13 +1,10 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; class CBJCompCard extends StatelessWidget { const CBJCompCard({ @@ -43,16 +40,11 @@ class CBJCompCard extends StatelessWidget { if (compEntity.entityTypes.getOrCrash() == EntityTypes.light.toString()) { return Center( - child: BlocProvider( - create: (context) => getIt(), - child: TextAtom( - compEntity.cbjEntityName.getOrCrash()!, - style: TextStyle( - color: Theme.of(context) - .textTheme - .bodyLarge! - .color, - ), + child: TextAtom( + compEntity.cbjEntityName.getOrCrash()!, + style: TextStyle( + color: + Theme.of(context).textTheme.bodyLarge!.color, ), ), ); diff --git a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart index d69dfba62..51a2dcdf8 100644 --- a/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart +++ b/lib/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/widgets/cbj_comp_card_with_devices_controll.dart @@ -1,13 +1,10 @@ import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:kt_dart/kt.dart'; class CBJCompCardWithDevicesControll extends StatelessWidget { @@ -29,13 +26,10 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { typesList.add( ColoredBox( color: Colors.yellowAccent.withOpacity(0.3), - child: BlocProvider( - create: (context) => getIt(), - child: TextAtom( - 'Type: ${deviceEntity.entityTypes.getOrCrash()}', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + child: TextAtom( + 'Type: ${deviceEntity.entityTypes.getOrCrash()}', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, ), ), ), @@ -67,83 +61,53 @@ class CBJCompCardWithDevicesControll extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Container( - margin: const EdgeInsets.all(15.0), - padding: const EdgeInsets.all(3.0), - decoration: BoxDecoration( - border: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - color: Colors.purpleAccent.withOpacity(0.2), - ), - child: Column( - children: [ - Container( - decoration: BoxDecoration( - border: Border( - top: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - bottom: BorderSide( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - ), + return Container( + margin: const EdgeInsets.all(15.0), + padding: const EdgeInsets.all(3.0), + decoration: BoxDecoration( + border: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + color: Colors.purpleAccent.withOpacity(0.2), + ), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + border: Border( + top: BorderSide( + color: Theme.of(context).textTheme.bodyLarge!.color!, ), - child: devicesTypes(context), - ), - const SizedBox( - height: 30, - ), - state.map( - initial: (_) => TextAtom( - 'Initial', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - actionInProgress: (_) => TextAtom( - 'actionInProgress', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - deleteFailure: (_) => TextAtom( - 'deleteFailure', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - deleteSuccess: (_) => TextAtom( - 'deleteSuccess', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), + bottom: BorderSide( + color: Theme.of(context).textTheme.bodyLarge!.color!, ), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Colors.greenAccent, - ), - ), - onPressed: () { - context.router.replace( - ConfigureNewCbjCompRoute(cbjCompEntity: cbjCompEntity), - ); - }, - child: TextAtom( - 'Set up computer', - style: TextStyle( - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - ), + ), + child: devicesTypes(context), + ), + const SizedBox( + height: 30, + ), + TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Colors.greenAccent, ), - ], + ), + onPressed: () { + context.router.replace( + ConfigureNewCbjCompRoute(cbjCompEntity: cbjCompEntity), + ); + }, + child: TextAtom( + 'Set up computer', + style: TextStyle( + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + ), ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart index e053c96aa..eb6050801 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/rooms_blinds_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/settings_page_of_blinds.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/blinds/w import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Blinds page that will call the blind widgets file and add background @@ -42,66 +38,34 @@ class RoomsBlindsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: Container( + width: MediaQuery.of(context).size.width, + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - width: MediaQuery.of(context).size.width, - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Blinds', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Blinds', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsBlindsWidget( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsBlindsWidget( + roomEntity: roomEntity, + roomColorGradiant: roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart index 72fb76a58..82f46f237 100644 --- a/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/blinds/widgets/rooms_blinds_widget.dart @@ -65,7 +65,7 @@ class _RoomsBlindsWidgetState extends State { @override Widget build(BuildContext context) { - if (devices.isNotEmpty()) { + if (devices.isEmpty()) { return SingleChildScrollView( reverse: true, padding: const EdgeInsets.only(bottom: 15), diff --git a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart index 8369726f2..130c529d4 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/rooms_boilers_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/settings_page_of_boilers.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/boilers/ import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Boilers page that will call the lamps widgets file and add background @@ -42,66 +38,34 @@ class RoomsBoilersPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: Container( + width: MediaQuery.of(context).size.width, + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - width: MediaQuery.of(context).size.width, - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Boilers', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Boilers', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsBoilersWidget( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsBoilersWidget( + roomEntity: roomEntity, + roomColorGradiant: roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart index b8ab9a45d..a4cd233a5 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/boilers_widget.dart @@ -71,31 +71,32 @@ class _BoilersWidgetState extends State { margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.temperatureThreeQuarters, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.temperatureThreeQuarters, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(value)), + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.temperatureThreeQuarters, + color: Color(0xFFF8E3A1), + ), + inactiveIcon: Icon( + FontAwesomeIcons.temperatureThreeQuarters, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + onToggle: (bool value) => _onChange(value), + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart index 766984c5f..5786bbb5f 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/room_boilers.dart @@ -72,9 +72,10 @@ class RoomBoilers extends StatelessWidget { height: 3, ), Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: BoilersWidget(deviceEntityTemp)), + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: BoilersWidget(deviceEntityTemp), + ), ], ), ); diff --git a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart index fc6624a5a..cd957add2 100644 --- a/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/boilers/widgets/rooms_boilers_widget.dart @@ -45,8 +45,9 @@ class _RoomsBoilersWidgetState extends State { } Future _boilersReceived( - dartz.Either, KtList> - failureOrDevices) async { + dartz.Either, KtList> + failureOrDevices, + ) async { final KtList devicesTemp = failureOrDevices.fold( (f) => const KtList.empty(), (d) => d.map((v) => v! as GenericBoilerDE).toMutableList(), diff --git a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart index 079d9a1c0..bbd4ec031 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/rooms_lights_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/settings_page_of_lights.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/w import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Lights page that will call the lamps widgets file and add background @@ -40,64 +36,32 @@ class RoomsLightsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: Container( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Lights', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Lights', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - ), - Expanded( - child: RoomsLightsWidget( - roomEntity: roomEntity, - roomColorGradiant: roomColorGradiant!, - ), - ), - ], + Expanded( + child: RoomsLightsWidget( + roomEntity: roomEntity, + roomColorGradiant: roomColorGradiant!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart index f8bf06bf6..4c12b4dd8 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart @@ -1,26 +1,44 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show light toggles in a container with the background color from smart room /// object -class DimmableLightWidget extends StatelessWidget { +class DimmableLightWidget extends StatefulWidget { const DimmableLightWidget(this._deviceEntity); final GenericDimmableLightDE _deviceEntity; - void _onChange(BuildContext context, bool value) { - context.read().add( - LightToggleEvent.changeAction( - deviceEntity: _deviceEntity, - changeToState: value, - ), - ); + @override + State createState() => _DimmableLightWidgetState(); +} + +class _DimmableLightWidgetState extends State { + double brightness = 100; + + Future _onChange(bool value) async { + if (value) { + await IDeviceRepository.instance.turnOnDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } else { + await IDeviceRepository.instance.turnOffDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } + } + + Future _changeBrightness(double value) async { + brightness = value; + + IDeviceRepository.instance.changeBrightnessDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + brightnessToChange: value.round(), + ); } @override @@ -28,8 +46,8 @@ class DimmableLightWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity.lightSwitchState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.lightSwitchState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -45,102 +63,90 @@ class DimmableLightWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return ColoredBox( - color: Colors.white, - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(horizontal: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: TextAtom( - _deviceEntity.cbjEntityName.getOrCrash()!, - style: const TextStyle( - overflow: TextOverflow.clip, - fontSize: 20.0, - color: Colors.black, - ), - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all(), - inactiveSwitchBorder: Border.all(), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.solidLightbulb, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.lightbulb, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(context, value), - ), + return ColoredBox( + color: Colors.white, + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(horizontal: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: TextAtom( + widget._deviceEntity.cbjEntityName.getOrCrash()!, + style: const TextStyle( + overflow: TextOverflow.clip, + fontSize: 20.0, + color: Colors.black, ), - ], + ), ), - ), - const SizedBox( - height: 3, - ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Row( - children: [ - const FaIcon( - FontAwesomeIcons.solidSun, - color: Colors.blueGrey, + Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all(), + inactiveSwitchBorder: Border.all(), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.solidLightbulb, + color: Color(0xFFF8E3A1), ), - Expanded( - child: Slider( - thumbColor: Colors.white, - activeColor: Colors.orangeAccent.shade100, - inactiveColor: Colors.grey, - value: state.brightness, - divisions: 100, - min: 1, - max: 100, - onChanged: (brightness) { - context.read().add( - LightToggleEvent.changeBrightness( - deviceEntity: _deviceEntity, - brightness: brightness, - ), - ); - }, - ), + inactiveIcon: Icon( + FontAwesomeIcons.lightbulb, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - SizedBox( - width: 45, - child: TextAtom( - '${state.brightness.round()}%', - style: const TextStyle(color: Colors.black), - ), - ), - ], + onToggle: _onChange, + ), + ), + ], + ), + ), + const SizedBox( + height: 3, + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Row( + children: [ + const FaIcon( + FontAwesomeIcons.solidSun, + color: Colors.blueGrey, + ), + Expanded( + child: Slider( + thumbColor: Colors.white, + activeColor: Colors.orangeAccent.shade100, + inactiveColor: Colors.grey, + value: brightness, + divisions: 100, + min: 1, + max: 100, + onChanged: _changeBrightness, + ), + ), + SizedBox( + width: 45, + child: TextAtom( + '${brightness.round()}%', + style: const TextStyle(color: Colors.black), + ), ), - ), - ], + ], + ), ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart index 36718a70f..f1a0acaf9 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/light_widget.dart @@ -1,8 +1,7 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -11,15 +10,18 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class LightWidget extends StatelessWidget { const LightWidget(this._deviceEntity); - final GenericLightDE? _deviceEntity; + final GenericLightDE _deviceEntity; - void _onChange(BuildContext context, bool value) { - context.read().add( - LightToggleEvent.changeAction( - deviceEntity: _deviceEntity!, - changeToState: value, - ), - ); + Future _onChange(bool value) async { + if (value) { + await IDeviceRepository.instance.turnOnDevices( + devicesId: [_deviceEntity.uniqueId.getOrCrash()], + ); + } else { + await IDeviceRepository.instance.turnOffDevices( + devicesId: [_deviceEntity.uniqueId.getOrCrash()], + ); + } } @override @@ -27,8 +29,8 @@ class LightWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity!.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity!.lightSwitchState!.getOrCrash(); + final deviceState = _deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = _deviceEntity.lightSwitchState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -44,44 +46,36 @@ class LightWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.solidLightbulb, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.lightbulb, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(context, value) - // _onChange(context, value), - - , - ), - ); - }, + return Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.solidLightbulb, + color: Color(0xFFF8E3A1), + ), + inactiveIcon: Icon( + FontAwesomeIcons.lightbulb, + color: Theme.of(context).textTheme.bodyLarge!.color, + ), + onToggle: _onChange, + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart index b07449ccc..505d972af 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart @@ -1,18 +1,21 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; -import 'package:provider/src/provider.dart'; class LightColorMods extends StatefulWidget { const LightColorMods({ - required this.state, required this.deviceEntity, + this.brightness = 100, + this.colorTemperature = 4500, + this.hsvColor, }); - final LightToggleState state; final GenericRgbwLightDE deviceEntity; + final int colorTemperature; + final HSVColor? hsvColor; + final double brightness; @override State createState() { @@ -21,23 +24,63 @@ class LightColorMods extends StatefulWidget { } class _LightColorMods extends State { - late Widget colorModeWidget; - int colorModFocus = 0; - - late LightToggleState _state; - late GenericRgbwLightDE _deviceEntity; + late int colorTemperature; + late HSVColor hsvColor; + late double brightness; @override void initState() { super.initState(); + hsvColor = widget.hsvColor ?? HSVColor.fromColor(Colors.white); + colorTemperature = widget.colorTemperature; + brightness = widget.brightness; + _initialized(); + } - context.read().add( - LightToggleEvent.initialized( - rgbwLightDe: widget.deviceEntity, - ), - ); + Future _initialized() async { + final GenericRgbwLightDE rgbwLightDe = widget.deviceEntity; + + int lightColorTemperature = + int.parse(rgbwLightDe.lightColorTemperature.getOrCrash()); + + if (lightColorTemperature > 10000) { + lightColorTemperature = 10000; + } + + double lightBrightness = + double.parse(rgbwLightDe.lightBrightness.getOrCrash()); + + if (lightBrightness > 100) { + lightBrightness = 100; + } + + setState(() { + colorTemperature = lightColorTemperature; + brightness = lightBrightness; + }); + } + + Future _changeColorTemperature(int newColorTemperature) async { + setState(() { + colorTemperature = newColorTemperature; + }); + IDeviceRepository.instance.changeColorTemperatureDevices( + devicesId: [widget.deviceEntity.uniqueId.getOrCrash()], + colorTemperatureToChange: newColorTemperature, + ); } + Future _changeHsvColor(HSVColor newHsvColor) async { + hsvColor = newHsvColor; + IDeviceRepository.instance.changeHsvColorDevices( + devicesId: [widget.deviceEntity.uniqueId.getOrCrash()], + hsvColorToChange: newHsvColor, + ); + } + + late Widget colorModeWidget; + int colorModFocus = 0; + Widget getWhiteModeWidget() { return Container( height: 100, @@ -55,16 +98,11 @@ class _LightColorMods extends State { ), child: Slider( activeColor: Colors.black.withOpacity(0.8), - value: _state.colorTemperature.toDouble(), + value: colorTemperature.toDouble(), min: 900, max: 10000, onChanged: (double newRating) { - context.read().add( - LightToggleEvent.changeColorTemperature( - deviceEntity: _deviceEntity, - newColorTemperature: newRating.toInt(), - ), - ); + _changeColorTemperature(newRating.toInt()); }, ), ); @@ -75,15 +113,8 @@ class _LightColorMods extends State { height: 100, width: double.infinity, child: ColorPickerArea( - _state.hsvColor, - (HSVColor color) { - context.read().add( - LightToggleEvent.changeHsvColor( - deviceEntity: _deviceEntity, - newHsvColor: color, - ), - ); - }, + hsvColor, + _changeHsvColor, PaletteType.hsvWithValue, ), ); @@ -120,7 +151,8 @@ class _LightColorMods extends State { color: (colorModFocus == 0) ? Colors.red : Colors.grey, fontSize: 18, ), - ), onPressed: () { + ), + onPressed: () { _showWhiteMode(); }, ), @@ -131,7 +163,8 @@ class _LightColorMods extends State { color: (colorModFocus == 1) ? Colors.red : Colors.grey, fontSize: 18, ), - ), onPressed: () { + ), + onPressed: () { _showColorMode(); }, ), @@ -144,8 +177,6 @@ class _LightColorMods extends State { @override Widget build(BuildContext context) { - _state = widget.state; - _deviceEntity = widget.deviceEntity; if (colorModFocus == 0) { colorModeWidget = getWhiteModeWidget(); } else { diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart index 711ff218a..8482acbf8 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart @@ -1,27 +1,76 @@ import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/light_color_mods.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_switch/flutter_switch.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Show light toggles in a container with the background color from smart room /// object -class RgbwLightWidget extends StatelessWidget { +class RgbwLightWidget extends StatefulWidget { const RgbwLightWidget(this._deviceEntity); final GenericRgbwLightDE _deviceEntity; - void _onChange(BuildContext context, bool value) { - context.read().add( - LightToggleEvent.changeAction( - deviceEntity: _deviceEntity, - changeToState: value, - ), - ); + @override + State createState() => _RgbwLightWidgetState(); +} + +class _RgbwLightWidgetState extends State { + int colorTemperature = 4500; + HSVColor hsvColor = HSVColor.fromColor(Colors.white); + double brightness = 100; + + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + final GenericRgbwLightDE rgbwLightDe = widget._deviceEntity; + + int lightColorTemperature = + int.parse(rgbwLightDe.lightColorTemperature.getOrCrash()); + + if (lightColorTemperature > 10000) { + lightColorTemperature = 10000; + } + + double lightBrightness = + double.parse(rgbwLightDe.lightBrightness.getOrCrash()); + + if (lightBrightness > 100) { + lightBrightness = 100; + } + + setState(() { + colorTemperature = lightColorTemperature; + brightness = lightBrightness; + }); + } + + Future _changeState(bool changeToState) async { + if (changeToState) { + await IDeviceRepository.instance.turnOnDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } else { + await IDeviceRepository.instance.turnOffDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + ); + } + } + + Future _changeBrightness(double value) async { + brightness = value; + + IDeviceRepository.instance.changeBrightnessDevices( + devicesId: [widget._deviceEntity.uniqueId.getOrCrash()], + brightnessToChange: value.round(), + ); } @override @@ -29,8 +78,8 @@ class RgbwLightWidget extends StatelessWidget { final Size screenSize = MediaQuery.of(context).size; final double sizeBoxWidth = screenSize.width * 0.25; - final deviceState = _deviceEntity.entityStateGRPC.getOrCrash(); - final deviceAction = _deviceEntity.lightSwitchState!.getOrCrash(); + final deviceState = widget._deviceEntity.entityStateGRPC.getOrCrash(); + final deviceAction = widget._deviceEntity.lightSwitchState!.getOrCrash(); bool toggleValue = false; Color toggleColor = Colors.blueGrey; @@ -46,103 +95,91 @@ class RgbwLightWidget extends StatelessWidget { } } - return BlocConsumer( - listener: (context, state) {}, - builder: (context, state) { - return ColoredBox( - color: Colors.white, - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(horizontal: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: TextAtom( - _deviceEntity.cbjEntityName.getOrCrash()!, - style: const TextStyle( - overflow: TextOverflow.clip, - fontSize: 20.0, - color: Colors.black, - ), - ), + return ColoredBox( + color: Colors.white, + child: Column( + children: [ + Container( + margin: const EdgeInsets.symmetric(horizontal: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: TextAtom( + widget._deviceEntity.cbjEntityName.getOrCrash()!, + style: const TextStyle( + overflow: TextOverflow.clip, + fontSize: 20.0, + color: Colors.black, ), - Container( - margin: const EdgeInsets.symmetric(vertical: 5), - width: sizeBoxWidth + 15, - child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.065, - toggleSize: screenSize.height * 0.065, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all(), - inactiveSwitchBorder: Border.all(), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: const Icon( - FontAwesomeIcons.solidLightbulb, - color: Color(0xFFF8E3A1), - ), - inactiveIcon: Icon( - FontAwesomeIcons.lightbulb, - color: Theme.of(context).textTheme.bodyLarge!.color, - ), - onToggle: (bool value) => _onChange(context, value), - ), - ), - ], + ), ), - ), - const SizedBox( - height: 3, - ), - LightColorMods(state: state, deviceEntity: _deviceEntity), - Container( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: Row( - children: [ - const FaIcon( - FontAwesomeIcons.solidSun, - color: Colors.blueGrey, - ), - Expanded( - child: Slider( - thumbColor: Colors.white, - activeColor: Colors.orangeAccent.shade100, - inactiveColor: Colors.grey, - value: state.brightness, - divisions: 100, - min: 1, - max: 100, - onChanged: (brightness) { - context.read().add( - LightToggleEvent.changeBrightness( - deviceEntity: _deviceEntity, - brightness: brightness, - ), - ); - }, - ), + Container( + margin: const EdgeInsets.symmetric(vertical: 5), + width: sizeBoxWidth + 15, + child: FlutterSwitch( + width: screenSize.width * 0.25, + height: screenSize.height * 0.065, + toggleSize: screenSize.height * 0.065, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all(), + inactiveSwitchBorder: Border.all(), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: const Icon( + FontAwesomeIcons.solidLightbulb, + color: Color(0xFFF8E3A1), ), - SizedBox( - width: 45, - child: TextAtom( - '${state.brightness.round()}%', - style: const TextStyle(color: Colors.black), - ), + inactiveIcon: Icon( + FontAwesomeIcons.lightbulb, + color: Theme.of(context).textTheme.bodyLarge!.color, ), - ], + onToggle: _changeState, + ), + ), + ], + ), + ), + const SizedBox( + height: 3, + ), + LightColorMods(deviceEntity: widget._deviceEntity), + Container( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Row( + children: [ + const FaIcon( + FontAwesomeIcons.solidSun, + color: Colors.blueGrey, + ), + Expanded( + child: Slider( + thumbColor: Colors.white, + activeColor: Colors.orangeAccent.shade100, + inactiveColor: Colors.grey, + value: brightness, + divisions: 100, + min: 1, + max: 100, + onChanged: _changeBrightness, + ), + ), + SizedBox( + width: 45, + child: TextAtom( + '${brightness.round()}%', + style: const TextStyle(color: Colors.black), + ), ), - ), - ], + ], + ), ), - ); - }, + ], + ), ); } } diff --git a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart index 2090cde47..29fb628c8 100644 --- a/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart +++ b/lib/presentation/pages/device_full_screen_page/lights/widgets/room_lights.dart @@ -4,8 +4,6 @@ import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstr import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cybear_jinni/application/light_toggle/light_toggle_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/error_lights_device_card_widget.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/dimmable_light_widget.dart'; @@ -13,7 +11,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/w import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/lights_widgets/rgb_light_widgets/rgbw_light_widget.dart'; import 'package:cybear_jinni/utils.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:kt_dart/collection.dart'; @@ -76,10 +73,7 @@ class RoomLights extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, - child: BlocProvider( - create: (context) => getIt(), - child: LightWidget(deviceEntityTemp), - ), + child: LightWidget(deviceEntityTemp), ), ], ), @@ -111,12 +105,7 @@ class RoomLights extends StatelessWidget { final List widgetsForRow = []; for (final GenericDimmableLightDE lightDE in lightsList) { - widgetsForRow.add( - BlocProvider( - create: (context) => getIt(), - child: DimmableLightWidget(lightDE), - ), - ); + widgetsForRow.add(DimmableLightWidget(lightDE)); } return widgetsForRow; @@ -129,12 +118,7 @@ class RoomLights extends StatelessWidget { final List widgetsForRow = []; for (final GenericRgbwLightDE lightDE in lightsList) { - widgetsForRow.add( - BlocProvider( - create: (context) => getIt(), - child: RgbwLightWidget(lightDE), - ), - ); + widgetsForRow.add(RgbwLightWidget(lightDE)); } return widgetsForRow; diff --git a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart index ea4d7e1b5..e46a3bcda 100644 --- a/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/printers/rooms_printers_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers/settings_page_of_printers.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/printers import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Printers page that will call the lamps widgets file and add background @@ -43,65 +39,33 @@ class RoomsPrintersPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: DecoratedBox( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: DecoratedBox( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Smart Computers', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Smart Computers', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsPrintersWidget( - roomEntity, - roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsPrintersWidget( + roomEntity, + roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart index 9046d3302..f1c6b45f6 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_computers/rooms_smart_computers_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_computers/settings_page_of_smart_computers.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_co import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// SmartComputers page that will call the lamps widgets file and add background @@ -43,65 +39,33 @@ class RoomsSmartComputersPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: DecoratedBox( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: DecoratedBox( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Smart Computers', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Smart Computers', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsSmartComputersWidget( - roomEntity, - roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsSmartComputersWidget( + roomEntity, + roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart index c786c714f..ffa071556 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/rooms_smart_plugs_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_plugs/settings_page_of_smart_plug.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_pl import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// SmartPlugs page that will call the lamps widgets file and add background @@ -43,65 +39,33 @@ class RoomsSmartPlugsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: Container( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'SmartPlugs', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'SmartPlugs', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsSmartPlugsWidget( - roomEntity, - roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsSmartPlugsWidget( + roomEntity, + roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart index 8a7eefcc2..c399e6e38 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_plugs/widgets/rooms_smart_plugs_widget.dart @@ -48,8 +48,9 @@ class _RoomsSmartPlugsWidgetState extends State { } Future _devicesReceived( - dartz.Either, KtList> - failureOrDevices) async { + dartz.Either, KtList> + failureOrDevices, + ) async { final KtList devicesTemp = failureOrDevices.fold( (f) => const KtList.empty(), (d) => d.map((v) => v!).toMutableList(), diff --git a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart index 2e5cdb72a..c00b7b329 100644 --- a/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart +++ b/lib/presentation/pages/device_full_screen_page/smart_tv/rooms_smart_tvs_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv/settings_page_of_smart_tvs.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/smart_tv import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// SmartTvs page that will call the lamps widgets file and add background @@ -43,65 +39,33 @@ class RoomsSmartTvsPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: DecoratedBox( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: DecoratedBox( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Smart Tvs', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant!.listOfColors!.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Smart Tvs', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant!.listOfColors!.last, - ), - Expanded( - child: RoomsSmartTvsWidget( - roomEntity, - roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsSmartTvsWidget( + roomEntity, + roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart index 7be96c9c2..36d1f44b7 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/rooms_switches_page.dart @@ -1,8 +1,5 @@ -import 'package:another_flushbar/flushbar_helper.dart'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/core/theme_data.dart'; import 'package:cybear_jinni/presentation/core/types_to_pass.dart'; import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches/settings_page_of_switches.dart'; @@ -10,7 +7,6 @@ import 'package:cybear_jinni/presentation/pages/device_full_screen_page/switches import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; /// Switches page that will call the lamps widgets file and add background @@ -43,65 +39,33 @@ class RoomsSwitchesPage extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt(), + return Scaffold( + appBar: AppBar( + toolbarHeight: 0, + backgroundColor: Colors.black, + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + body: Container( + decoration: BoxDecoration( + gradient: BackgroundGradient.getBackground(context), ), - ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Scaffold( - appBar: AppBar( - toolbarHeight: 0, - backgroundColor: Colors.black, - systemOverlayStyle: SystemUiOverlayStyle.dark, - ), - body: Container( - decoration: BoxDecoration( - gradient: BackgroundGradient.getBackground(context), + child: Column( + children: [ + TopNavigationBar( + pageName: 'Switches', + rightIcon: null, + rightIconFunction: cogFunction, + leftIcon: FontAwesomeIcons.arrowLeft, + leftIconFunction: backButtonFunction, + backgroundColor: roomColorGradiant?.listOfColors?.last, ), - child: Column( - children: [ - TopNavigationBar( - pageName: 'Switches', - rightIcon: null, - rightIconFunction: cogFunction, - leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: backButtonFunction, - backgroundColor: roomColorGradiant?.listOfColors?.last, - ), - Expanded( - child: RoomsSwitchesWidget( - roomEntity, - roomColorGradiant!.listOfColors!, - ), - ), - ], + Expanded( + child: RoomsSwitchesWidget( + roomEntity, + roomColorGradiant!.listOfColors!, + ), ), - ), + ], ), ), ); diff --git a/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart b/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart index d2b9efe2e..6a8a31185 100644 --- a/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart +++ b/lib/presentation/pages/device_full_screen_page/switches/widgets/switches_widget.dart @@ -72,31 +72,32 @@ class _SwitchWidgetState extends State { margin: const EdgeInsets.symmetric(vertical: 5), width: sizeBoxWidth + 15, child: FlutterSwitch( - width: screenSize.width * 0.25, - height: screenSize.height * 0.0655, - toggleSize: screenSize.height * 0.0655, - value: toggleValue, - borderRadius: 25.0, - padding: 0.0, - activeToggleColor: const Color(0xFF2F363D), - inactiveToggleColor: Colors.deepPurple, - activeSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - inactiveSwitchBorder: Border.all( - color: Theme.of(context).textTheme.bodyLarge!.color!, - ), - activeColor: toggleColor, - inactiveColor: toggleColor, - activeIcon: Icon( - MdiIcons.lightSwitch, - color: Colors.white, - ), - inactiveIcon: Icon( - MdiIcons.lightSwitch, - color: Colors.white70, - ), - onToggle: (bool value) => _changeAction(value)), + width: screenSize.width * 0.25, + height: screenSize.height * 0.0655, + toggleSize: screenSize.height * 0.0655, + value: toggleValue, + borderRadius: 25.0, + padding: 0.0, + activeToggleColor: const Color(0xFF2F363D), + inactiveToggleColor: Colors.deepPurple, + activeSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + inactiveSwitchBorder: Border.all( + color: Theme.of(context).textTheme.bodyLarge!.color!, + ), + activeColor: toggleColor, + inactiveColor: toggleColor, + activeIcon: Icon( + MdiIcons.lightSwitch, + color: Colors.white, + ), + inactiveIcon: Icon( + MdiIcons.lightSwitch, + color: Colors.white70, + ), + onToggle: (bool value) => _changeAction(value), + ), ); } } diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart index acb94bd99..63c1b3cb1 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/devices_in_the_room_blocks/switches_in_the_room_block.dart @@ -42,7 +42,9 @@ class SwitchesInTheRoomBlock extends StatelessWidget { final ListOfColors roomColorGradiant; Future _turnOffAllSwitches( - BuildContext context, List? switchesIdToTurnOff) async { + BuildContext context, + List? switchesIdToTurnOff, + ) async { FlushbarHelper.createLoading( message: 'Turning Off all switches', linearProgressIndicator: const LinearProgressIndicator(), @@ -52,7 +54,9 @@ class SwitchesInTheRoomBlock extends StatelessWidget { } Future _turnOnAllSwitches( - BuildContext context, List? switchesIdToTurnOn) async { + BuildContext context, + List? switchesIdToTurnOn, + ) async { FlushbarHelper.createLoading( message: 'Turning On all switches', linearProgressIndicator: const LinearProgressIndicator(), diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart index e6c65785a..531d8dd78 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart @@ -1,146 +1,213 @@ +import 'dart:async'; + +import 'package:cbj_integrations_controller/domain/room/i_room_repository.dart'; +import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; +import 'package:cbj_integrations_controller/domain/room/room_failures.dart'; +import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; +import 'package:cybear_jinni/domain/device/devices_failures.dart'; +import 'package:cybear_jinni/domain/device/i_device_repository.dart'; +import 'package:cybear_jinni/infrastructure/phone_hub/phone_hub.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/pages/device_full_screen_page/lights/widgets/critical_light_failure_display_widget.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/rooms_widgets/rooms_list_view_widget.dart'; +import 'package:dartz/dartz.dart' as dartz; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import 'package:kt_dart/collection.dart'; + +class SmartDevicesByRooms extends StatefulWidget { + @override + State createState() => _SmartDevicesByRoomsState(); +} + +class _SmartDevicesByRoomsState extends State { + KtList rooms = const KtList.empty(); + KtList devices = + const KtList.empty(); + KtList listOfDevices = [null].toImmutableList(); + KtList listOfRooms = [null].toImmutableList(); + + StreamSubscription>>? + _roomStreamSubscription; + + StreamSubscription< + dartz.Either>>? + _deviceStreamSubscription; + late RoomEntity discoveredRoom; + + Future _roomsReceived( + dartz.Either> failureOrRooms, + ) async { + final KtList roomsTemp = failureOrRooms.fold( + (f) => const KtList.empty(), + (d) => d, + ); + setState(() { + rooms = roomsTemp; + }); + } + + Future _devicesReceived( + dartz.Either, KtList> + failureOrDevices, + ) async { + final KtList devicesTemp = failureOrDevices.fold( + (f) => const KtList.empty(), + (d) => d, + ); + setState(() { + devices = devicesTemp; + }); + } + + @override + void initState() { + super.initState(); + _watchAllStarted(); + } + + Future _watchAllStarted() async { + discoveredRoom = RoomEntity( + uniqueId: + RoomUniqueId.fromUniqueString('00000000-0000-0000-0000-000000000000'), + cbjEntityName: RoomDefaultName('Discovered'), + roomTypes: RoomTypes(const []), + roomDevicesId: RoomDevicesId(const []), + roomScenesId: RoomScenesId(const []), + roomRoutinesId: RoomRoutinesId(const []), + roomBindingsId: RoomBindingsId(const []), + roomMostUsedBy: RoomMostUsedBy(const []), + roomPermissions: RoomPermissions(const []), + background: RoomBackground( + 'https://images.pexels.com/photos/459654/pexels-photo-459654.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260', + ), + ); + + final Map allDevice = + await PhoneHub().getAllDevices; + + for (final String deviceId in allDevice.keys) { + discoveredRoom.addDeviceId(deviceId); + } + _roomsReceived(dartz.right([discoveredRoom].toImmutableList())); + + _devicesReceived(dartz.right(allDevice.values.toImmutableList())); + + _roomStreamSubscription = + IRoomRepository.instance.watchAllRooms().listen((eventWatch) { + _roomsReceived(eventWatch); + }); + + _deviceStreamSubscription = + IDeviceRepository.instance.watchAllDevices().listen((eventWatch) { + _devicesReceived(eventWatch); + }); + } + + @override + Future dispose() async { + await _roomStreamSubscription?.cancel(); + await _deviceStreamSubscription?.cancel(); + return super.dispose(); + } -class SmartDevicesByRooms extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return state.map( - initial: (_) => Container(), - loadInProgress: (_) => const Column( - mainAxisAlignment: MainAxisAlignment.center, + if (devices.isEmpty()) { + return GestureDetector( + onTap: () { + Fluttertoast.showToast( + msg: 'Add new device by pressing the plus button', + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.CENTER, + backgroundColor: Colors.blueGrey, + textColor: Theme.of(context).textTheme.bodyLarge!.color, + fontSize: 16.0, + ); + }, + child: SingleChildScrollView( + reverse: true, + padding: const EdgeInsets.only(bottom: 15), + child: Column( children: [ - CircularProgressIndicatorAtom(), - SizedBox( - height: 30, + Container( + margin: const EdgeInsets.symmetric(vertical: 30), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + fit: BoxFit.fitHeight, + ), ), - TextAtom( - 'Searching for CyBear Jinni Hub', - style: TextStyle( - fontSize: 18, - color: Colors.blue, + Align( + alignment: Alignment.topCenter, + child: TextAtom( + 'Devices list is empty', + style: TextStyle( + fontSize: 30, + color: Theme.of(context).primaryColor, + ), ), ), ], ), - loadSuccess: (state) { - if (state.devices.size != 0) { - final Map> - tempDevicesByRooms = >{}; - - final List devicesList = - state.devices.iter.toList(); - - return SingleChildScrollView( - reverse: true, - child: Column( - children: [ - if (tempDevicesByRooms.length == 1) - Container( - margin: const EdgeInsets.only(bottom: 10), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - width: 200.0, - fit: BoxFit.fill, - ), - ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 50), - margin: const EdgeInsets.symmetric(vertical: 20), - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.2), - borderRadius: BorderRadius.circular(10), - ), - child: Stack( - children: [ - TextAtom( - 'Areas', - style: TextStyle( - fontSize: 35, - foreground: Paint() - ..style = PaintingStyle.stroke - ..strokeWidth = 3 - ..color = Colors.black.withOpacity(0.2), - ), - ), - TextAtom( - 'Areas', - style: TextStyle( - fontSize: 35, - color: - Theme.of(context).textTheme.bodyLarge!.color, - ), - ), - ], - ), - ), - RoomsListViewWidget( - tempDevicesByRooms: tempDevicesByRooms, - devicesList: devicesList, - roomsList: state.rooms.iter.toList(), - ), - ], + ), + ); + } + final Map> tempDevicesByRooms = + >{}; + + final List devicesList = devices.iter.toList(); + + return SingleChildScrollView( + reverse: true, + child: Column( + children: [ + if (tempDevicesByRooms.length == 1) + Container( + margin: const EdgeInsets.only(bottom: 10), + alignment: Alignment.center, + child: const ImageAtom( + 'assets/cbj_logo.png', + width: 200.0, + fit: BoxFit.fill, + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 50), + margin: const EdgeInsets.symmetric(vertical: 20), + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.2), + borderRadius: BorderRadius.circular(10), + ), + child: Stack( + children: [ + TextAtom( + 'Areas', + style: TextStyle( + fontSize: 35, + foreground: Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 3 + ..color = Colors.black.withOpacity(0.2), + ), ), - ); - } else { - return GestureDetector( - onTap: () { - Fluttertoast.showToast( - msg: 'Add new device by pressing the plus button', - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.CENTER, - backgroundColor: Colors.blueGrey, - textColor: Theme.of(context).textTheme.bodyLarge!.color, - fontSize: 16.0, - ); - }, - child: SingleChildScrollView( - reverse: true, - padding: const EdgeInsets.only(bottom: 15), - child: Column( - children: [ - Container( - margin: const EdgeInsets.symmetric(vertical: 30), - alignment: Alignment.center, - child: const ImageAtom( - 'assets/cbj_logo.png', - fit: BoxFit.fitHeight, - ), - ), - Align( - alignment: Alignment.topCenter, - child: TextAtom( - 'Devices list is empty', - style: TextStyle( - fontSize: 30, - color: Theme.of(context).primaryColor, - ), - ), - ), - ], + TextAtom( + 'Areas', + style: TextStyle( + fontSize: 35, + color: Theme.of(context).textTheme.bodyLarge!.color, ), ), - ); - } - }, - loadFailure: (state) { - return CriticalLightFailureDisplay( - failure: state.devicesFailure, - ); - }, - error: (Error value) { - return const TextAtom('Error'); - }, - ); - }, + ], + ), + ), + RoomsListViewWidget( + tempDevicesByRooms: tempDevicesByRooms, + devicesList: devicesList, + roomsList: rooms.iter.toList(), + ), + ], + ), ); } } diff --git a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart index 84c3a3524..deadec805 100644 --- a/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart +++ b/lib/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_widgets.dart @@ -1,14 +1,9 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; -import 'package:another_flushbar/flushbar_helper.dart'; -import 'package:cybear_jinni/application/devices/device_actor/device_actor_bloc.dart'; -import 'package:cybear_jinni/application/devices/device_watcher/device_watcher_bloc.dart'; -import 'package:cybear_jinni/injection.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; import 'package:cybear_jinni/presentation/pages/change_room_for_devices/change_room_for_devices_page.dart'; import 'package:cybear_jinni/presentation/pages/home_page/tabs/smart_devices_tab/smart_devices_by_rooms.dart'; import 'package:cybear_jinni/presentation/pages/shared_widgets/top_navigation_bar.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class SmartDevicesWidgets extends StatelessWidget { @@ -52,59 +47,21 @@ class SmartDevicesWidgets extends StatelessWidget { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => getIt() - ..add( - const DeviceWatcherEvent.watchAllStarted(), - ), + return Column( + children: [ + TopNavigationBar( + pageName: 'Devices', + rightIcon: Icons.more_vert, + rightIconFunction: userCogFunction, + leftIcon: FontAwesomeIcons.solidLightbulb, + leftIconFunction: (BuildContext context) {}, + // rightSecondIcon: FontAwesomeIcons.magnifyingGlass, + // rightSecondFunction: rightSecondFunction, ), - BlocProvider( - create: (context) => getIt(), + Expanded( + child: SmartDevicesByRooms(), ), ], - child: MultiBlocListener( - listeners: [ - BlocListener( - listener: (context, state) { - state.maybeMap( - deleteFailure: (state) { - FlushbarHelper.createError( - duration: const Duration(seconds: 5), - message: 'Error', - // state.devicesFailure.map( - // unexpected: (_) => - // 'Unexpected error occured while deleting,' + - // 'please contact support.', - // insufficientPermission: (_) => - // 'Insufficient permissions ❌', - // unableToUpdate: (_) => 'Impossible error', - // ), - ).show(context); - }, - orElse: () {}, - ); - }, - ), - ], - child: Column( - children: [ - TopNavigationBar( - pageName: 'Devices', - rightIcon: Icons.more_vert, - rightIconFunction: userCogFunction, - leftIcon: FontAwesomeIcons.solidLightbulb, - leftIconFunction: (BuildContext context) {}, - // rightSecondIcon: FontAwesomeIcons.magnifyingGlass, - // rightSecondFunction: rightSecondFunction, - ), - Expanded( - child: SmartDevicesByRooms(), - ), - ], - ), - ), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index e2be039aa..26cfc09c0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,8 +43,6 @@ dependencies: auto_route: ^7.8.4 # Automatically resizes text to fit perfectly within its bounds. auto_size_text: ^3.0.0 - # Helps implement the BLoC pattern. - bloc: ^8.1.2 cbj_integrations_controller: path: ../cbj_integrations_controller # git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git From 3ca2e171e42702ab48f990b90c5829cde0974ee2 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 1 Dec 2023 23:04:40 +0200 Subject: [PATCH 15/15] Back to git version of packages --- pubspec.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 26cfc09c0..33082b8a1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,11 +44,11 @@ dependencies: # Automatically resizes text to fit perfectly within its bounds. auto_size_text: ^3.0.0 cbj_integrations_controller: - path: ../cbj_integrations_controller -# git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git +# path: ../cbj_integrations_controller + git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git cbj_smart_device_flutter: - path: ../cbj_smart_device_flutter -# git: https://github.com/CyBear-Jinni/cbj_smart_device_flutter.git +# path: ../cbj_smart_device_flutter + git: https://github.com/CyBear-Jinni/cbj_smart_device_flutter.git # Copy text from and to clipboard clipboard: ^0.1.3 # Package to create, convert, alter, and compare colors in a variety of colorspaces.