diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index d1c2ad24..8f026f3e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -35,7 +35,7 @@ class _HomePageWidgetState extends State { ], child: Builder( builder: (context) { - context.read().updateProfile(context); + // context.read().updateProfile(context); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 42b16d9c..eecd26d9 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -71,7 +71,6 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @override Future processLocals(BuildContext context) async { try { - await LicenseRepositoryImpl().cleanLicense(); final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); final bool? isError = response.jsonBody['error']; diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 39916fc1..d30f7523 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; class LocalsRepositoryImpl implements LocalsRepository { final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); @@ -12,7 +13,7 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - final bool response = await remoteDataSource.processLocals(context); + final bool response = await LicenseRepositoryImpl().updateLicense(); context.read().add(LocalProfileEvent()); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index d79f115c..9abbd435 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -36,10 +36,10 @@ class LocalProfileBloc extends Bloc { emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); } - void updateProfile(BuildContext context) { - add(LocalProfileEvent()); - LocalsRepositoryImpl().update(context); - } + // void updateProfile(BuildContext context) { + // add(LocalProfileEvent()); + // LocalsRepositoryImpl().update(context); + // } } class LocalProfileComponentModel extends FlutterFlowModel { diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 7f692ccb..d786151c 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -15,6 +15,7 @@ class MenuRepositoryImpl implements MenuRepository { @override Future> generateMenuEntries(List menuOptions, EnumMenuItem item) async { + log('Generating menu entries for $item'); List entries = []; try { for (var opt in menuOptions) { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 5835bd60..54230ed4 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -13,7 +13,7 @@ abstract class LicenseRemoteDataSource { Future fetchLicenses(bool isNewVersion); Future cleanLicense(); Future processLicense(); - Future setupLicense(Database database, bool isNewVersion); + Future setupLicense(Database database, bool isNewVersion); } class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @@ -22,8 +22,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { LicenseRemoteDataSourceImpl._internal(); - final StreamController _completerController = StreamController.broadcast(); - Stream get streamCompleterController => _completerController.stream; + final StreamController completerController = StreamController.broadcast(); + Stream get streamCompleterController => completerController.stream; @override @@ -36,7 +36,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } @override - Future setupLicense(Database database, bool isNewVersion) async { + Future setupLicense(Database database, bool isNewVersion) async { + log('Setting up license...'); final License license = await License.getLicense(isNewVersion); final List inactiveModuleKey = license.modules @@ -63,11 +64,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); } - LicenseRepositoryImpl.license.add(true); + return true; } @override Future fetchLicenses(bool isNewVersion) async { + log('Fetching licenses...'); try { final response = await PhpGroup.getLicense(); final dynamic responseBody = response.jsonBody; @@ -83,9 +85,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } if (responseBody == []) { - await setupLicense(DatabaseStorage.database, isNewVersion); - LicenseRepositoryImpl.license.add(false); - return false; + return await setupLicense(DatabaseStorage.database, isNewVersion); } List> saveOperations = []; @@ -95,15 +95,10 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } } await Future.wait(saveOperations); - - LicenseRepositoryImpl.license.add(true); - _completerController.add(null); - return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); - await setupLicense(DatabaseStorage.database, isNewVersion); - return false; + return await setupLicense(DatabaseStorage.database, isNewVersion); } } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 48cd0436..d2b2ae43 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -18,12 +18,16 @@ class LicenseRepositoryImpl implements LicenseRepository { static get stream => license.stream; Future updateLicense() async { + LicenseRepositoryImpl.license.add(false); + bool result = false; final bool isNewVersion = await localDataSource.isNewVersion(); - await remoteDataSource.setupLicense(database, isNewVersion); + result = await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { - return await remoteDataSource.fetchLicenses(isNewVersion); + result = await remoteDataSource.fetchLicenses(isNewVersion); } - return false; + + LicenseRepositoryImpl.license.add(result); + return result; } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 8460a47f..258e81d7 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -46,6 +46,9 @@ class DatabaseStorage { if (version >= 3) { await database.execute(updateDisplayTrigger); } + if (version >= 4) { + await database.execute(updatePeopleDisplayTrigger); + } } Future _onUpgrade(Database database, int oldVersion, int newVersion) async {