Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved privacy policy from main app to digit component (#569) #570

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/health_campaign_field_worker_app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import 'blocs/localization/localization.dart';
import 'blocs/project/project.dart';
import 'data/local_store/app_shared_preferences.dart';
import 'data/network_manager.dart';
import 'data/remote_client.dart';
import 'data/repositories/remote/bandwidth_check.dart';
import 'data/repositories/remote/localization.dart';
import 'data/repositories/remote/mdms.dart';
import 'router/app_navigator_observer.dart';
Expand Down Expand Up @@ -201,6 +203,11 @@ class MainApplicationState extends State<MainApplication>
),
BlocProvider(
create: (ctx) => ProjectBloc(
bandwidthCheckRepository: BandwidthCheckRepository(
DioClient().dio,
bandwidthPath:
envConfig.variables.checkBandwidthApiPath,
),
mdmsRepository: MdmsRepository(widget.client),
dashboardRemoteRepository:
DashboardRemoteRepository(widget.client),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import '../../data/local_store/no_sql/schema/app_configuration.dart';
import '../../data/local_store/no_sql/schema/row_versions.dart';
import '../../data/local_store/no_sql/schema/service_registry.dart';
import '../../data/local_store/secure_store/secure_store.dart';
import '../../data/repositories/remote/bandwidth_check.dart';
import '../../data/repositories/remote/mdms.dart';
import '../../models/app_config/app_config_model.dart';
import '../../models/auth/auth_model.dart';
import '../../models/entities/roles_type.dart';
import '../../utils/background_service.dart';
import '../../utils/environment_config.dart';
import '../../utils/utils.dart';

Expand All @@ -35,6 +37,8 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {
final Isar isar;
final MdmsRepository mdmsRepository;

final BandwidthCheckRepository bandwidthCheckRepository;

/// Project Staff Repositories
final RemoteRepository<ProjectStaffModel, ProjectStaffSearchModel>
projectStaffRemoteRepository;
Expand Down Expand Up @@ -103,6 +107,7 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {

ProjectBloc({
LocalSecureStore? localSecureStore,
required this.bandwidthCheckRepository,
required this.projectStaffRemoteRepository,
required this.projectRemoteRepository,
required this.projectStaffLocalRepository,
Expand Down Expand Up @@ -169,6 +174,7 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {
}

FutureOr<void> _loadOnline(ProjectEmitter emit) async {
final batchSize = await _getBatchSize();
final userObject = await localSecureStore.userRequestModel;
final uuid = userObject?.uuid;

Expand Down Expand Up @@ -289,7 +295,7 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {

if (projects.isNotEmpty) {
try {
await _loadProjectFacilities(projects);
await _loadProjectFacilities(projects, batchSize);
} catch (_) {
emit(
state.copyWith(
Expand Down Expand Up @@ -360,7 +366,8 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {
);
}

FutureOr<void> _loadProjectFacilities(List<ProjectModel> projects) async {
FutureOr<void> _loadProjectFacilities(
List<ProjectModel> projects, int batchSize) async {
final projectFacilities = await projectFacilityRemoteRepository.search(
ProjectFacilitySearchModel(
projectId: projects.map((e) => e.id).toList(),
Expand All @@ -371,6 +378,7 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {

final facilities = await facilityRemoteRepository.search(
FacilitySearchModel(tenantId: envConfig.variables.tenantId),
limit: batchSize,
);

await facilityLocalRepository.bulkCreate(facilities);
Expand Down Expand Up @@ -584,8 +592,6 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {
loading: false,
syncError: ProjectSyncErrorType.boundary,
));

return;
}

emit(state.copyWith(
Expand All @@ -594,6 +600,25 @@ class ProjectBloc extends Bloc<ProjectEvent, ProjectState> {
syncError: null,
));
}

FutureOr<int> _getBatchSize() async {
try {
final configs = await isar.appConfigurations.where().findAll();

final double speed = await bandwidthCheckRepository.pingBandwidthCheck(
bandWidthCheckModel: null,
);

int configuredBatchSize = getBatchSizeToBandwidth(
speed,
configs,
isDownSync: true,
);
return configuredBatchSize;
} catch (e) {
rethrow;
}
Comment on lines +610 to +625
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unnecessary Try-Catch Block with Immediate Rethrow in _getBatchSize

In the _getBatchSize method, the try-catch block catches exceptions and immediately rethrows them without any handling. This is unnecessary and can be removed to simplify the code. If exception handling is required, consider logging the error or implementing specific error handling logic.

Apply this diff to remove the unnecessary try-catch block:

-    try {
       final configs = await isar.appConfigurations.where().findAll();

       final double speed = await bandwidthCheckRepository.pingBandwidthCheck(
         bandWidthCheckModel: null,
       );

       int configuredBatchSize = getBatchSizeToBandwidth(
         speed,
         configs,
         isDownSync: true,
       );
       return configuredBatchSize;
-    } catch (e) {
-      rethrow;
-    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
final configs = await isar.appConfigurations.where().findAll();
final double speed = await bandwidthCheckRepository.pingBandwidthCheck(
bandWidthCheckModel: null,
);
int configuredBatchSize = getBatchSizeToBandwidth(
speed,
configs,
isDownSync: true,
);
return configuredBatchSize;
} catch (e) {
rethrow;
}
final configs = await isar.appConfigurations.where().findAll();
final double speed = await bandwidthCheckRepository.pingBandwidthCheck(
bandWidthCheckModel: null,
);
int configuredBatchSize = getBatchSizeToBandwidth(
speed,
configs,
isDownSync: true,
);
return configuredBatchSize;

}
}

@freezed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ class PerformSyncDown {
.whereNotNull()
.toList(),
),
limit: bandwidthModel.batchSize,
);

for (var element in operationGroupedEntity.value) {
Expand Down
30 changes: 28 additions & 2 deletions apps/health_campaign_field_worker_app/lib/pages/login.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:digit_components/digit_components.dart';
import 'package:digit_components/models/privacy_notice/privacy_notice_model.dart';
import 'package:digit_components/widgets/atoms/digit_toaster.dart';
import 'package:digit_components/widgets/privacy_notice/privacy_component.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:reactive_forms/reactive_forms.dart';
Expand All @@ -11,7 +13,7 @@ import '../router/app_router.dart';
import '../utils/environment_config.dart';
import '../utils/i18_key_constants.dart' as i18;
import '../widgets/localized.dart';
import '../widgets/privacy_notice/privacy_component.dart';


@RoutePage()
class LoginPage extends LocalizedStatefulWidget {
Expand Down Expand Up @@ -140,7 +142,7 @@ class _LoginPageState extends LocalizedState<LoginPage> {
form.control(_privacyCheck).setValidators([Validators.requiredTrue]);
form.control(_privacyCheck).updateValueAndValidity();
return PrivacyComponent(
privacyPolicy: privacyPolicyJson,
privacyPolicy: convertToPrivacyPolicyModel(privacyPolicyJson),
formControlName: _privacyCheck,
text: localizations
.translate(i18.privacyPolicy.privacyNoticeText),
Expand Down Expand Up @@ -237,3 +239,27 @@ class _LoginPageState extends LocalizedState<LoginPage> {
)
});
}


// convert to privacy notice model
PrivacyNoticeModel? convertToPrivacyPolicyModel(PrivacyPolicy? privacyPolicy) {
return PrivacyNoticeModel(
header: privacyPolicy?.header ?? '',
module: privacyPolicy?.module ?? '',
active: privacyPolicy?.active,
contents: privacyPolicy?.contents?.map((content) => ContentNoticeModel(
header: content.header,
descriptions: content.descriptions?.map((description) => DescriptionNoticeModel(
text: description.text,
type: description.type,
isBold: description.isBold,
subDescriptions: description.subDescriptions?.map((subDescription) => SubDescriptionNoticeModel(
text: subDescription.text,
type: subDescription.type,
isBold: subDescription.isBold,
isSpaceRequired: subDescription.isSpaceRequired,
)).toList(),
)).toList(),
)).toList(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:referral_reconciliation/blocs/app_localization.dart'
as referral_reconciliation_localization;
import 'package:registration_delivery/blocs/app_localization.dart'
as registration_delivery_localization;
import 'package:digit_components/blocs/localization.dart' as component_localization;

import '../blocs/localization/app_localization.dart';
import '../data/local_store/no_sql/schema/app_configuration.dart';
Expand Down Expand Up @@ -59,6 +60,10 @@ getAppLocalizationDelegates({
digit_dss_localization.DashboardLocalization.getDelegate(
LocalizationLocalRepository().returnLocalizationFromSQL(sql) as Future,
appConfig.languages!,
)
),
component_localization.ComponentLocalization.getDelegate(
LocalizationLocalRepository().returnLocalizationFromSQL(sql) as Future,
appConfig.languages!,
),
];
}
22 changes: 10 additions & 12 deletions apps/health_campaign_field_worker_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ packages:
description:
path: "packages/dart_mappable_builder"
ref: master
resolved-ref: "9b887d24c05459c027a92391869d4c10b440e00f"
resolved-ref: e3d8ac43f70568b4a17c200cae5cde285050ef23
url: "https://github.com/egovernments/health-campaign-field-worker-app/"
source: git
version: "4.2.0"
Expand Down Expand Up @@ -494,17 +494,16 @@ packages:
dependency: "direct main"
description:
name: digit_components
sha256: "9cca4d9a546037080afe02b6ade82fdf01574e11f5656ad12120fd6966578616"
sha256: dcdab9542149022cb66241c3c379ca96916f8b6116e585f4799748d859a2ca49
url: "https://pub.dev"
source: hosted
version: "1.0.1+1"
version: "1.0.2"
digit_data_model:
dependency: "direct main"
description:
name: digit_data_model
sha256: "0b81e96636496b56b4f9c5d918690a17d8985d6b131e0ab54968eb5471ee4f54"
url: "https://pub.dev"
source: hosted
path: "../../packages/digit_data_model"
relative: true
source: path
version: "1.0.3+1"
digit_dss:
dependency: "direct main"
Expand Down Expand Up @@ -1119,11 +1118,10 @@ packages:
inventory_management:
dependency: "direct main"
description:
name: inventory_management
sha256: "1a5976ab807666629704f559730d5418e1c723fed898df2cc6e7d9807f813b6f"
url: "https://pub.dev"
source: hosted
version: "1.0.3+2"
path: "../../packages/inventory_management"
relative: true
source: path
version: "1.0.3+4"
io:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions apps/health_campaign_field_worker_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
sqlite3_flutter_libs: ^0.5.10
path_provider: ^2.0.11
path: ^1.8.2
digit_components: ^1.0.1+1
digit_components: ^1.0.2
auto_route: ^7.8.4
flutter_bloc: ^8.1.1
collection: ^1.16.0
Expand Down Expand Up @@ -67,7 +67,7 @@ dependencies:
camera: ^0.10.5+7
attendance_management: ^1.0.2+1
digit_scanner: ^1.0.3+1
inventory_management: ^1.0.3+2
inventory_management: ^1.0.3+4
referral_reconciliation: ^1.0.2+1
digit_data_model: ^1.0.3+1
registration_delivery: ^1.0.3+1
Expand Down
3 changes: 3 additions & 0 deletions packages/digit_components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.2
* Added privacy notice component

## 1.0.1+1
* Changed similar dialogs to a common hideDialog

Expand Down
2 changes: 1 addition & 1 deletion packages/digit_components/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1+1"
version: "1.0.2"
easy_stepper:
dependency: transitive
description:
Expand Down
52 changes: 52 additions & 0 deletions packages/digit_components/lib/blocs/localization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

import 'localization_delegates.dart';


// Class responsible for handling component localization
class ComponentLocalization {
final Locale locale;
final Future<dynamic> localizedStrings;
final List<dynamic> languages;

ComponentLocalization(this.locale, this.localizedStrings, this.languages);

// Method to get the current localization instance from context
static ComponentLocalization of(BuildContext context) {
return Localizations.of<ComponentLocalization>(context, ComponentLocalization)!;
}

static final List<dynamic> _localizedStrings = <dynamic>[];

// Method to get the delegate for localization
static LocalizationsDelegate<ComponentLocalization> getDelegate(
Future<dynamic> localizedStrings, List<dynamic> languages) =>
ComponentLocalizationDelegate(localizedStrings, languages);

// Method to load localized strings
Future<bool> load() async {
_localizedStrings.clear();
// Iterate over localized strings and filter based on locale
for (var element in await localizedStrings) {
if (element.locale == '${locale.languageCode}_${locale.countryCode}') {
_localizedStrings.add(element);
}
}

return true;
}

// Method to translate a given localized value
String translate(String localizedValues) {

if (_localizedStrings.isEmpty) {
return localizedValues;
} else {
final index = _localizedStrings.indexWhere(
(medium) => medium.code == localizedValues,
);

return index != -1 ? _localizedStrings[index].message : localizedValues;
}
}
}
33 changes: 33 additions & 0 deletions packages/digit_components/lib/blocs/localization_delegates.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

import 'localization.dart';


class ComponentLocalizationDelegate
extends LocalizationsDelegate<ComponentLocalization> {
final Future<dynamic> localizedStrings;
final List<dynamic> languages;

const ComponentLocalizationDelegate(this.localizedStrings, this.languages);

@override
bool isSupported(Locale locale) {
return languages.map((e) {
final results = e.value.split('_');
if (results.isNotEmpty) return results.first;
}).contains(locale.languageCode);
}

@override
Future<ComponentLocalization> load(Locale locale) async {
ComponentLocalization localization =
ComponentLocalization(locale, localizedStrings, languages);
await localization.load();
return localization;
}

@override
bool shouldReload(covariant LocalizationsDelegate<ComponentLocalization> old) {
return true;
}
}
Loading
Loading