Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Turskyi <[email protected]>
  • Loading branch information
Turskyi committed Feb 23, 2024
1 parent 1bdf9f6 commit 439e06a
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ abstract class TerrorismSponsor {
}

extension TerrorismSponsorList on List<TerrorismSponsor> {
bool sponsoredBy(ProductInfo product) {
return _isSponsoredByOtherRussiaSponsors(product) ||
_isSponsoredByAnyTerrorismSponsor(product);
}
bool sponsoredBy(ProductInfo product) =>
_isSponsoredByOtherRussiaSponsors(product) ||
_isSponsoredByAnyTerrorismSponsor(product);

bool _isSponsoredByOtherRussiaSponsors(ProductInfo product) {
return _otherRussiaSponsors.contains(product.brand.toLowerCase());
}
bool _isSponsoredByOtherRussiaSponsors(ProductInfo product) =>
_otherTerrorismSponsors.contains(product.brand.toLowerCase());

bool _isSponsoredByAnyTerrorismSponsor(ProductInfo product) {
return any(
Expand All @@ -48,22 +46,20 @@ extension TerrorismSponsorList on List<TerrorismSponsor> {
bool _isSponsorNameNotEmptyAndMatchesProductBrandOrName(
TerrorismSponsor terrorismSponsor,
ProductInfo product,
) {
return terrorismSponsor.name.isNotEmpty &&
(product.brand.toLowerCase().trim() ==
terrorismSponsor.name.toLowerCase().trim() ||
product.name.toLowerCase().trim() ==
terrorismSponsor.name.toLowerCase().trim());
}
) =>
terrorismSponsor.name.isNotEmpty &&
(product.brand.toLowerCase().trim() ==
terrorismSponsor.name.toLowerCase().trim() ||
product.name.toLowerCase().trim() ==
terrorismSponsor.name.toLowerCase().trim());

bool _isSponsorBrandsNotEmptyAndContainsProductBrand(
TerrorismSponsor terrorismSponsor,
ProductInfo product,
) {
return terrorismSponsor.brands.isNotEmpty &&
product.brand.isNotEmpty &&
_doesSponsorBrandsContainProductBrand(terrorismSponsor, product);
}
) =>
terrorismSponsor.brands.isNotEmpty &&
product.brand.isNotEmpty &&
_doesSponsorBrandsContainProductBrand(terrorismSponsor, product);

bool _doesSponsorBrandsContainProductBrand(
TerrorismSponsor terrorismSponsor,
Expand All @@ -73,14 +69,13 @@ extension TerrorismSponsorList on List<TerrorismSponsor> {
return lowerCaseBrands.contains(product.brand.toLowerCase());
}

List<String> _getLowerCaseBrands(TerrorismSponsor terrorismSponsor) {
return terrorismSponsor.brands
.split(', ')
.map((String brand) => brand.toLowerCase())
.toList();
}
List<String> _getLowerCaseBrands(TerrorismSponsor terrorismSponsor) =>
terrorismSponsor.brands
.split(', ')
.map((String brand) => brand.toLowerCase())
.toList();

List<String> get _otherRussiaSponsors => <String>[
List<String> get _otherTerrorismSponsors => <String>[
'twix',
'quaker',
'nestlé',
Expand Down
1 change: 0 additions & 1 deletion core/interface_adapters/lib/interface_adapters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export 'src/env/env.dart';
export 'src/gateways/product_info_gateway_impl.dart';
export 'src/gateways/settings_gateway_impl.dart';
export 'src/ui/app/app.dart';
export 'src/ui/modules/home/home_event.dart';
export 'src/ui/modules/home/home_presenter.dart';
export 'src/ui/modules/home/view/home_view.dart';
export 'src/ui/modules/photo/photo_presenter.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:entities/entities.dart';
part of 'home_presenter.dart';

sealed class HomeEvent {
@immutable
abstract class HomeEvent {
const HomeEvent();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:bloc/bloc.dart';
import 'package:entities/entities.dart';
import 'package:interface_adapters/src/error_message_extractor.dart';
import 'package:interface_adapters/src/ui/modules/home/home_event.dart';
import 'package:meta/meta.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:use_cases/use_cases.dart';

part 'home_event.dart';
part 'home_view_model.dart';

class HomePresenter extends Bloc<HomeEvent, HomeViewModel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:interface_adapters/src/ui/modules/home/home_event.dart';
import 'package:interface_adapters/src/ui/modules/home/home_presenter.dart';
import 'package:interface_adapters/src/ui/modules/home/view/widgets/fab.dart';
import 'package:interface_adapters/src/ui/modules/home/view/widgets/language_selector.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:interface_adapters/src/ui/modules/home/home_event.dart';
import 'package:interface_adapters/src/ui/modules/home/home_presenter.dart';
import 'package:interface_adapters/src/ui/res/color/material_colors.dart';
import 'package:interface_adapters/src/ui/res/resources.dart';
Expand Down
3 changes: 2 additions & 1 deletion core/interface_adapters/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ dependencies:
flutter_translate: ^4.0.4

html: ^0.15.4
meta: any
mobile_scanner: ^4.0.0

# For launching a URL. Supports web, phone, SMS, and email schemes.
package_info_plus: ^5.0.1
path_provider: ^2.1.2
url_launcher: ^6.2.4
url_launcher: ^6.2.5

use_cases:
path: ../domain/use_cases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ class RussiaSponsorResponse implements TerrorismSponsor {
String? id,
DateTime? createdTime,
Fields? fields,
}) {
return RussiaSponsorResponse(
id: id ?? this.id,
createdTime: createdTime ?? this.createdTime,
fields: fields ?? this.fields,
);
}
}) =>
RussiaSponsorResponse(
id: id ?? this.id,
createdTime: createdTime ?? this.createdTime,
fields: fields ?? this.fields,
);

@override
bool operator ==(Object other) {
Expand Down
2 changes: 1 addition & 1 deletion lib/di/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:dio/dio.dart';
import 'package:entities/entities.dart';
import 'package:ethical_scanner/data/data_sources/local/local_data_source_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/remote_data_source_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/logging_interceptor/logging_interceptor_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/logging_interceptor_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/retrofit_client/retrofit_client.dart';
import 'package:interface_adapters/interface_adapters.dart';
import 'package:use_cases/use_cases.dart';
Expand Down
2 changes: 1 addition & 1 deletion test/remote_data_source_impl_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dio/dio.dart';
import 'package:entities/entities.dart';
import 'package:ethical_scanner/data/data_sources/remote/remote_data_source_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/logging_interceptor/logging_interceptor_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/logging_interceptor_impl.dart';
import 'package:ethical_scanner/data/data_sources/remote/rest/retrofit_client/retrofit_client.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
Expand Down

0 comments on commit 439e06a

Please sign in to comment.