Skip to content

Commit

Permalink
Add optional store scanner beep sound (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Turskyi <[email protected]>
  • Loading branch information
Turskyi authored Feb 12, 2024
1 parent c56abb2 commit 6eef5a7
Show file tree
Hide file tree
Showing 32 changed files with 421 additions and 138 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/flutter_ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build & upload to Firebase App Distribution
on:
push:
branches:
- six
branches-ignore:
- master

jobs:
build_apk:
Expand Down
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"spellright.language": [
"en"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext",
"Log"
],
"spellright.parserByClass": {
"Log": {
"parser": "plain"
}
}
}
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ 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
* [Open Food Facts](https://world.openfoodfacts.org);
* [Ukrainian national agency on corruption prevention | INTERNATIONAL SPONSORS OF WAR](https://sanctions.nazk.gov.ua/en/boycott/);
* [Yale chief executive leadership institute| List of Companies

- [Open Food Facts](https://world.openfoodfacts.org);
- [Ukrainian national agency on corruption prevention | INTERNATIONAL SPONSORS OF WAR](https://sanctions.nazk.gov.ua/en/boycott/);
- [Yale chief executive leadership institute | List of Companies
Leaving and Staying in Russia](https://www.yalerussianbusinessretreat.com/);
[U.S. bureau of counterterrorism | State Sponsors of Terrorism](https://www.state.gov/state-sponsors-of-terrorism/);
* [Global Forum Against Terrorism](https://www.gfatf.org/threats/countries-who-support-terrorism/).
- [U.S. bureau of counterterrorism | State Sponsors of Terrorism](https://www.state.gov/state-sponsors-of-terrorism/);
- [European Parliament](https://www.europarl.europa.eu/delegations/en/recognising-the-russian-federation-as-a-/product-details/20221124DPU34521).

The app aims to help you shop with confidence and conscience.
For more information, please visit the project website at https://ethical-scanner.turskyi.com.
Expand Down Expand Up @@ -66,7 +67,7 @@ Ethical Scanner is an open source project and welcomes contributions from anyone
If you want to contribute to Ethical Scanner, you can follow these steps:

- Fork this repository and clone it to your local machine.
- Create a new branch for your feature or bugfix.
- Create a new branch for your feature or bug-fix.
- Make your changes and commit them with a clear and descriptive message.
- Push your branch to your forked repository and create a pull request to the main repository.
- Wait for your pull request to be reviewed and merged.
Expand Down
12 changes: 6 additions & 6 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest
package="com.turskyi.ethical_scanner"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="6"
android:versionName="0.0.6">
package="com.turskyi.ethical_scanner"
android:versionCode="7"
android:versionName="0.0.7">

<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
Expand All @@ -25,7 +25,7 @@
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize"
tools:ignore="UnusedAttribute">
tools:ignore="Instantiatable,UnusedAttribute">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand Down
13 changes: 12 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.google.gms:google-services:4.4.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
}
}
Expand All @@ -21,6 +21,17 @@ allprojects {
google()
mavenCentral()
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
}

rootProject.buildDir = '../build'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ abstract interface class SettingsGateway {
Future<bool> saveLanguageIsoCodeAsFuture(String languageIsoCode);

String getLanguageIsoCode();

bool getSoundPreference();

Future<bool> saveSoundPreferenceAsFuture(bool isSoundOn);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:use_cases/use_cases.dart';

class GetSoundPreferenceUseCase implements UseCase<bool, Null> {
const GetSoundPreferenceUseCase(this._settingsGateway);

final SettingsGateway _settingsGateway;

@override
bool call([_]) => _settingsGateway.getSoundPreference();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:use_cases/use_cases.dart';

class SaveSoundPreferenceUseCase implements UseCase<Future<bool>, bool> {
const SaveSoundPreferenceUseCase(this._settingsGateway);

final SettingsGateway _settingsGateway;

@override
Future<bool> call([bool isSoundOn = false]) =>
_settingsGateway.saveSoundPreferenceAsFuture(isSoundOn);
}
16 changes: 9 additions & 7 deletions components/core/use_cases/lib/use_cases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
/// rules.
library use_cases;

export 'src/use_cases/use_case.dart';
export 'src/gateways/product_info_gateway.dart';
export 'src/gateways/settings_gateway.dart';
export 'src/use_cases/add_ingredients_use_case.dart';
export 'src/use_cases/get_language_use_case.dart';
export 'src/use_cases/get_precipitation_state_use_case.dart';
export 'src/use_cases/get_product_info_use_case.dart';
export 'src/use_cases/save_precipitation_state_use_case.dart';
export 'src/use_cases/get_sound_preference_use_case.dart';
export 'src/use_cases/save_language_use_case.dart';
export 'src/use_cases/get_precipitation_state_use_case.dart';
export 'src/use_cases/get_language_use_case.dart';
export 'src/use_cases/add_ingredients_use_case.dart';
export 'src/gateways/product_info_gateway.dart';
export 'src/gateways/settings_gateway.dart';
export 'src/use_cases/save_precipitation_state_use_case.dart';
export 'src/use_cases/save_sound_preference_use_case.dart';
export 'src/use_cases/use_case.dart';
Binary file not shown.
1 change: 1 addition & 0 deletions components/interface_adapters/lib/interface_adapters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ 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';
export 'src/ui/modules/photo/view/photo_view.dart';
export 'src/ui/modules/scan/scan_event.dart';
export 'src/ui/modules/scan/scan_presenter.dart';
export 'src/ui/modules/scan/view/scan_view.dart';
2 changes: 2 additions & 0 deletions components/interface_adapters/lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const String scanSoundAsset =
'components/interface_adapters/assets/audio/store_scanner_beep.mp3';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ abstract interface class LocalDataSource {
String getLanguageIsoCode();

Future<bool> saveLanguageIsoCode(String languageIsoCode);

Future<bool> saveSoundPreference(bool isSoundOn);

bool getSoundPreference();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ class SettingsGatewayImpl implements SettingsGateway {
@override
Future<bool> saveLanguageIsoCodeAsFuture(String languageIsoCode) =>
_localDataSource.saveLanguageIsoCode(languageIsoCode);

@override
bool getSoundPreference() => _localDataSource.getSoundPreference();

@override
Future<bool> saveSoundPreferenceAsFuture(bool isSoundOn) =>
_localDataSource.saveSoundPreference(isSoundOn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class HomePresenter extends Bloc<HomeEvent, HomeViewModel> {
this._getPrecipitationStateUseCase,
this._saveLanguageUseCase,
this._getLanguageUseCase,
) : super(const ReadyToScanState()) {
) : super(const LoadingHomeState()) {
on<LoadHomeEvent>(
(_, Emitter<HomeViewModel> emit) {
emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ sealed class ScanEvent {
const ScanEvent();
}

class LoadScannerEvent extends ScanEvent {
const LoadScannerEvent();
}

class PopBarcodeEvent extends ScanEvent {
const PopBarcodeEvent(this.barcode);
final String barcode;

final String? barcode;
}

class NavigateBackEvent extends ScanEvent {
const NavigateBackEvent();
}

class SoundToggleEvent extends ScanEvent {
const SoundToggleEvent();
}

class DetectedBarcodeEvent extends ScanEvent {
const DetectedBarcodeEvent(this.barcodeValue);

final String? barcodeValue;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
import 'package:bloc/bloc.dart';
import 'package:interface_adapters/src/ui/modules/scan/scan_event.dart';
import 'package:use_cases/use_cases.dart';

part 'scan_view_model.dart';

class ScanPresenter extends Bloc<ScanEvent, ScanViewModel> {
ScanPresenter() : super(const ScanningState()) {
ScanPresenter(
this._saveSoundPreferenceUseCase,
this._getSoundPreferenceUseCase,
) : super(const LoadingScanningState()) {
on<LoadScannerEvent>(
(_, Emitter<ScanViewModel> emit) {
emit(ScanningState(_getSoundPreferenceUseCase.call()));
},
);
on<PopBarcodeEvent>(
(PopBarcodeEvent event, Emitter<ScanViewModel> emit) =>
emit(ScanSuccessState(event.barcode)),
(PopBarcodeEvent event, Emitter<ScanViewModel> emit) {
if (event.barcode != null) {
emit(ScanSuccessState(event.barcode!));
} else {
emit(const CanceledScanningState());
}
},
);
on<NavigateBackEvent>(
(_, Emitter<ScanViewModel> emit) {
emit(const CanceledScanningState());
},
);

on<SoundToggleEvent>((
_,
Emitter<ScanViewModel> emit,
) async {
if (state is ScanningState) {
bool isSoundOn = !(state as ScanningState).isSoundOn;
bool isSaved = await _saveSoundPreferenceUseCase.call(isSoundOn);
if (isSaved) {
emit((state as ScanningState).copyWith(isSoundOn));
} else {
emit(const LoadingScanningState());
}
}
});

on<DetectedBarcodeEvent>(
(DetectedBarcodeEvent event, Emitter<ScanViewModel> emit) {
if (state is ScanningState) {
emit(
DetectedBarcodeState(
barcodeValue: event.barcodeValue,
isSoundOn: (state as ScanningState).isSoundOn,
),
);
}
},
);
}

final SaveSoundPreferenceUseCase _saveSoundPreferenceUseCase;
final GetSoundPreferenceUseCase _getSoundPreferenceUseCase;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@ sealed class ScanViewModel {
const ScanViewModel();
}

class LoadingScanningState extends ScanViewModel {
const LoadingScanningState();
}

class ScanningState extends ScanViewModel {
const ScanningState() : super();
const ScanningState(this.isSoundOn);

final bool isSoundOn;

ScanningState copyWith(bool? isSoundOn) =>
ScanningState(isSoundOn ?? this.isSoundOn);
}

class ScanSuccessState extends ScanViewModel {
const ScanSuccessState(this.barcode);

final String barcode;
}

class CanceledScanningState extends ScanViewModel {
const CanceledScanningState();
}

class DetectedBarcodeState extends ScanViewModel {
const DetectedBarcodeState({
required this.barcodeValue,
required this.isSoundOn,
});

final String? barcodeValue;
final bool isSoundOn;
}
Loading

0 comments on commit 6eef5a7

Please sign in to comment.