Skip to content

Commit

Permalink
Fix brand comparison (#8)
Browse files Browse the repository at this point in the history
* Add codemagic.yaml for CI/CD to publish app bundle to Google Play.

Signed-off-by: Dmytro Turskyi <[email protected]>

* Add scan page screenshot

Signed-off-by: Dmytro Turskyi <[email protected]>

* Update CI workflow and README badges

Added a step to the Flutter CI workflow to generate Dart environment
configuration files, ensuring that generated code is consistent with the
CI environment. Also updated the README to include dynamic badges that
reflect the code quality of the master branch after each push, providing
better visibility into the project's health.

Resolves ongoing build inconsistencies and improves project monitoring.

* move usage of the dart command after flutter set up in CI

Signed-off-by: Dmytro Turskyi <[email protected]>

* Add new utility functions module

Introduced a new 'util.dart' in the 'interface_adapters' library to
house shared utility functions, laying the groundwork for centralized
common operations which will enhance code reusability and maintenance.
This move aligns with the modular design goals and prepares for future
developments that require utility support.

* Enhanced error handling and sponsor checks

Updated the product info retrieval process to improve error handling
with detailed logging and fallback product information creation based on
input type. The retrieval now manages different input scenarios more
robustly, including the possibility of FormatException. It also includes
custom product info when specific patterns, such as websites or Amazon
ASIN, are detected.

The commit extends the functionality to check if product brands are
associated with terrorism sponsors, strengthening the validation against
a more comprehensive database.

Additionally, the `Fields` class within the `russia_sponsors_response`
model has been updated, making `name` a required field to ensure that
only entries with a valid name are processed. It also now includes a
`brands` field to accommodate multiple brands associated with a sponsor.

To support the parsing of exception sources as HTML, the `html`
dependency was added to the `pubspec.yaml`, facilitating the extraction
of user-friendly error messages.

Lastly, unnecessary data logging in `logging_interceptor_impl.dart` has
been eliminated to streamline the code and reduce log verbosity.

* Add downtime message extractor from HTML

Implemented a function to parse HTML and extract downtime messages for
user-facing platforms. The method searches for a specific element in the
given HTML and returns its textual content. If the element is not found,
a generic migration-related downtime message is returned. This ensures
users receive clear communication regarding service availability during
maintenance periods.

* Refine label for war sponsorship & error handling
enhancements

- Updated the label in `ProductInfoKey` to more accurately reflect
companies that sponsor war instead of terrorism.
- Generalized error extraction function to handle all error messages
consistently.
- Incorporated functionality to address potential war sponsorship
indication in the product info, enhancing user awareness with clickable
links for more information.
- Improved the reliability of the snow animation initiation in alignment
with the widget lifecycle.
- Optimized the remote data source handling to check for a specific
brand as a war sponsor and to align checks with the updated
`TerrorismSponsor` model.

Resolves issues related to user clarity and engagement regarding product
information, and enhances visual feature stability.

* Updated Flutter Release APK Build and App Version to 0.0.5(5)

Adjusted the Flutter CI workflow to include the `--no-tree-shake-icons`
option during the APK build process, ensuring that all icons are
preserved in the release build. This change resolves potential issues
with missing icons that may appear after the tree shaking optimization.
Additionally, the app version in `pubspec.yaml` has been incremented,
signifying a new iteration of the application in preparation for the
next release cycle.

* Optimize Flutter APK build in CI

Removed the `--no-tree-shake-icons` flag from the Flutter APK build step
to reduce build time and potentially decrease the APK size. This change
can result in a smaller set of icons being embedded in the APK, ensuring
that only the icons used in the app are packaged.

* Enhanced source attribution and clarified release
flow

Updated the README to include an additional data source on war sponsors
and refined the language for clarity. Reformatted the release process
description for more straightforward understanding. In the
AndroidManifest, added comments to suppress lint warnings. Improved
product brand comparison logic in the data source implementation to
match brands more accurately by trimming whitespace.

Resolves issues with data accuracy and maintainability.

---------

Signed-off-by: Dmytro Turskyi <[email protected]>
  • Loading branch information
Turskyi authored Jan 13, 2024
1 parent f7bc82a commit 9b3cf83
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The app allows you to customize your preferences based on
various criteria, such as human rights, environmental impact, animal well-being, and more.

The app uses the data from various sources, such as
[Don’t Fund War](https://dontfundwar.com/directory),
[Don’t Fund War](https://dontfundwar.com/directory), [NATIONAL AGENCY
ON CORRUPTION PREVENTION | INTERNATIONAL
SPONSORS OF WAR](https://sanctions.nazk.gov.ua/en/boycott/)
[Over 1,000 Companies Have Curtailed Operations in Russia—But Some Remain](https://som.yale.edu/story/2022/over-1000-companies-have-curtailed-operations-russia-some-remain),
[Yale CELI List of Companies Leaving and Staying in Russia](https://www.yalerussianbusinessretreat.com/),
[State Sponsors of Terrorism](https://www.state.gov/state-sponsors-of-terrorism/) and
Expand Down Expand Up @@ -106,10 +108,12 @@ rules operating on Critical Business Data.
#### Application Business Rules - `use_cases`

The `use_cases` module defines the business logic of the app.
It is a component that is independent of the development platform, in other words, it is written
It is a part that is independent of the development platform, in other words, it is written
purely in the
programming language and does not contain any elements from the platform. In the case of `Flutter`,
`use_cases` would be written purely in `Dart` without any `Flutter` elements. The reason for that is
programming language and doesn't contain any elements from the platform.
In the case of `Flutter`,
`use_cases` would be written purely in `Dart` without any `Flutter` elements.
The reason for that is
that `use_cases` should only be concerned with the business logic of the app,
not with the implementation details.

Expand Down Expand Up @@ -392,11 +396,17 @@ fields. This makes them very powerful tools that allow much more expression and

## Additional information

When it is time to release the whole system, the process proceeds from the bottom up. First the
`Entities` component is compiled, tested, and released. Then the same is done for interactors from
the `use_cases`. These components are followed by `interface_adapters` (
Presenters, View and ViewModels). `Frameworks & drivers` (`data` and `main`) go last. This process
is very clear to deal with. We know how to build the system
When it is time to release the system, the process proceeds from the bottom up.
First the
`Entities` component is compiled, tested, and released.
Then the same is done for interactors from
the `use_cases`.
These components are followed by `interface_adapters` (
Presenters, View and ViewModels).
(`data` and `main`) go last.
This process
is very clear to deal with.
We know how to build the system
because we understand the dependencies between its parts.

# Usage
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.VIBRATE" />
<!--suppress AndroidDomInspection -->
<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="Ethical Scanner">
<!--suppress AndroidDomInspection -->
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand All @@ -17,6 +19,7 @@
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<!--suppress AndroidDomInspection -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:html/dom.dart';
import 'package:html/parser.dart';

/// Extract the downtime message from the HTML response
String extractErrorMessage(String exceptionSource) {
final Document document = parse(exceptionSource);

// Extract the text content within the <div class="main-content"> element
final Element? mainContentElement = document.querySelector(
'div.main-content',
);
if (mainContentElement != null) {
final String message = mainContentElement.text.trim();
return message;
}

return 'We are currently undergoing a major migration, and our services, '
'including the Web platform, mobile app, API, and Producer Platform, '
'are temporarily unavailable.';
}
16 changes: 9 additions & 7 deletions lib/data/data_sources/remote/remote_data_source_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ class RemoteDataSourceImpl implements RemoteDataSource {
return productInfo.copyWith(
isTerrorismSponsor: productInfo.brand.toLowerCase() == 'twix' ||
terrorismSponsors is List<RussiaSponsorResponse> &&
terrorismSponsors.any((RussiaSponsorResponse response) {
return (response.fields.name.isNotEmpty &&
productInfo.brand.toLowerCase().contains(
response.fields.name.toLowerCase(),
)) ||
terrorismSponsors.any(
(RussiaSponsorResponse response) =>
(response.fields.name.isNotEmpty &&
productInfo.brand.toLowerCase().trim() ==
response.fields.name
.toLowerCase()
.trim()) ||
(response.fields.brands.isNotEmpty &&
response.fields.brands.toLowerCase().contains(
productInfo.brand.toLowerCase(),
));
}),
)),
),
);
}).onError((Object? e, StackTrace s) => productInfo);
} else {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.0.4+4
version: 0.0.5+5

environment:
sdk: '>=3.2.3 <4.0.0'
Expand Down

0 comments on commit 9b3cf83

Please sign in to comment.