Skip to content

Commit

Permalink
refactor: Boycott List JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Zied-Dahmani committed Nov 20, 2023
1 parent 5a4da88 commit 19bfa38
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ app.*.symbols
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock
!.vscode/settings.json
!.vscode/settings.json

# Play Store
key.properties
app/upload-keystore.jks
20 changes: 17 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}


android {
namespace "com.rebounddev.qataa"
compileSdkVersion flutter.compileSdkVersion
Expand Down Expand Up @@ -55,13 +62,20 @@ android {
multiDexEnabled true
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}

}

flutter {
Expand Down
63 changes: 63 additions & 0 deletions assets/boycott_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
"coca cola",
"coca-cola",
"fanta",
"sprite",
"pepsi",
"red bull",
"miranda",
"nestlé",
"lipton",
"nutella",
"kitkat",
"twix",
"kat",
"nesquik",
"carrefour",
"tang",
"milka",
"oreo",
"bounty",
"snickers",
"mars",
"galaxy",
"m&m's",
"danone",
"nescafé",
"knorr",
"flakes",
"ariel",
"gillette",
"rexona",
"axe",
"l'oreal",
"pringles",
"doritos",
"cheetos",
"lay's",
"signal",
"sensodyne",
"oral-b",
"colgate",
"crest",
"sunsilk",
"nivea",
"pantene",
"lux",
"dove",
"vansih",
"always",
"dettol",
"schwarzkopf",
"palmolive",
"fairy",
"pril",
"persil",
"tide",
"omo",
"shoulders",
"finish",
"vaseline",
"unilever",
"johnson's"
]
File renamed without changes
File renamed without changes
4 changes: 3 additions & 1 deletion lib/application/app_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import 'package:qataa/application/services/connectivity_service.dart';
import 'package:qataa/application/services/onboarding_service.dart';
import 'package:qataa/application/usecases/scan_barcode_use_case.dart';
import 'package:qataa/data/repositories/barcode_repository.dart';
import 'package:qataa/data/sources/remote/barcode_data_source.dart';
import 'package:qataa/data/sources/remote/boycott_data_source.dart';

class AppBindings implements Bindings {
@override
void dependencies() {
Get.lazyPut(() => ConnectivityService(), fenix: true);
Get.lazyPut(() => OnBoardingService(), fenix: true);
Get.lazyPut(() => ScanController(ScanBarcodeUseCase(BarcodeRepository())), fenix: true);
Get.lazyPut(() => ScanController(ScanBarcodeUseCase(BarcodeRepository(BarcodeDataSource(),BoycottDataSource()))), fenix: true);
}
}
14 changes: 7 additions & 7 deletions lib/application/controllers/scan_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ScanController extends GetxController {
final _verificationState = VerificationState().obs;
RxInterface<VerificationState> get rxIState => _verificationState;
VerificationState get state => _verificationState.value;
bool get isBlacklisted {
bool get isBoycotted {
VerificationLoadSuccess verificationLoadSuccess = _verificationState.value as VerificationLoadSuccess;
return verificationLoadSuccess.isBlacklisted;
return verificationLoadSuccess.isBoycotted;
}

static final _possibleFormats = BarcodeFormat.values.toList()..removeWhere((e) => e == BarcodeFormat.unknown);
Expand All @@ -45,8 +45,8 @@ class ScanController extends GetxController {
ScreenUtil.CustomSystemChrome(context);
if (result.rawContent.isNotEmpty) {
_verificationState.value = VerificationLoadInProgress();
final isBlacklisted = await _scanBarcodeUseCase.execute(result.rawContent);
_verificationState.value = VerificationLoadSuccess(isBlacklisted: isBlacklisted);
final isBoycotted = await _scanBarcodeUseCase.execute(result.rawContent);
_verificationState.value = VerificationLoadSuccess(isBoycotted: isBoycotted);
}
} catch (e) {
developer.log(e.toString(), name: 'Catch scanBarcode');
Expand All @@ -73,7 +73,7 @@ class ScanController extends GetxController {
final player1 = AudioPlayer();
final player2 = AudioPlayer();

if (isBlacklisted) {
if (isBoycotted) {
player2.play(AssetSource('sounds/baby-crying.mp3'));
player1.setVolume(0.3);
player1.play(AssetSource('sounds/explosion.mp3'));
Expand All @@ -86,10 +86,10 @@ class ScanController extends GetxController {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return BottomSheetContent(isBlacklisted: isBlacklisted);
return BottomSheetContent(isBoycotted: isBoycotted);
},
).whenComplete(() {
if (isBlacklisted) {
if (isBoycotted) {
player1.stop();
player2.stop();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/application/controllers/verification_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class VerificationState extends Equatable {
class VerificationLoadInProgress extends VerificationState {}

class VerificationLoadSuccess extends VerificationState {
final bool isBlacklisted;
final bool isBoycotted;

VerificationLoadSuccess({required this.isBlacklisted});
VerificationLoadSuccess({required this.isBoycotted});

@override
List<Object> get props => [isBlacklisted];
List<Object> get props => [isBoycotted];
}

class VerificationLoadFailure extends VerificationState {
Expand Down
10 changes: 5 additions & 5 deletions lib/config/locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class Locale implements Translations {
'appName': 'قاطع',
'scanTitle': 'ثبت قبل ماتشري',
'scanSubtitle': 'تنجم تكون سبب في تمويل الإبادة الي قاعد يقوم بها الكيان',
'blacklistedTitle': 'قاطع',
'blacklistSubtitle': 'الماركة تابعة الكيان بطريقة مباشرة ولا غير مباشرة',
'notBlacklistedTitle': 'تنجم تشري',
'notBlacklistSubtitle': 'كانك شاكك زيد ثبت و إسأل',
'boycottedTitle': 'قاطع',
'boycottedSubtitle': 'المنتج تابع الكيان بطريقة مباشرة أو غير مباشرة',
'supportedTitle': 'تنجم تشري',
'supportedSubtitle': 'كانك شاكك زيد ثبت و إسأل',
'productNotKnownTitle': 'منتج',
'productNotKnownSubtitle': 'معناش عليه معلومات',
'connectivityProblemTitle': 'إنترنت',
'connectivityProblemSubtitle': 'ثبت عندك إنترنت ولا',
'scanOnBoardingTitle': 'سكاني المنتج',
'scanOnBoardingBody': 'بش تعرفو ضمن القائمة السوداء ولا تنجم تشريه',
'scanOnBoardingBody': 'بش تعرفو ضمن قائمة المقاطعة ولا تنجم تشريه',
'emailOnBoardingTitle': 'استفسارات',
'emailOnBoardingBody': 'كان تحب تسأل على حاجة تنجم تبعثلنا بريد إلكتروني',
'alertTitle': 'تنبيه',
Expand Down
75 changes: 8 additions & 67 deletions lib/data/repositories/barcode_repository.dart
Original file line number Diff line number Diff line change
@@ -1,82 +1,23 @@
import 'package:qataa/data/sources/remote/barcode_data_source.dart';
import 'package:qataa/data/sources/remote/boycott_data_source.dart';
import 'package:qataa/domain/repositories/barcode_repository_interface.dart';

class BarcodeRepository implements IBarcodeRepository {
final BarcodeDataSource _barcodeDataProvider = BarcodeDataSource();
// TODO: fill the black list
final List<String> _blacklist = [
'coca',
'coca-cola',
'fanta',
'sprite',
'pepsi',
'bull',
'miranda',
'nestlé',
'lipton',
'nutella',
'kitkat',
'twix',
'kat',
'nesquik',
'carrefour',
'tang',
'milka',
'oreo',
'bounty',
'snickers',
'mars',
'galaxy',
"m&m's",
'danone'
'nescafé',
'knorr',
'flakes',
'ariel',
'gillette',
'rexona',
'axe',
"l'oreal",
'pringles',
'doritos',
'cheetos',
"lay's",
'signal',
'sensodyne',
'oral-b',
'colgate',
'crest',
'sunsilk',
'nivea',
'pantene',
'lux',
'dove',
'vansih',
'always',
'dettol',
'schwarzkopf',
'palmolive',
'fairy',
'pril',
'persil',
'tide',
'omo',
'shoulders',
'finish',
'vaseline',
'unilever',
"johnson's",
];
BarcodeRepository(this._barcodeDataProvider, this._boycottDataSource);

final BarcodeDataSource _barcodeDataProvider;
final BoycottDataSource _boycottDataSource;

@override
Future<bool> fetchBarcodeData(String barcode) async {
final boycottList = await _boycottDataSource.fetchBoycottList();
final result = await _barcodeDataProvider.fetchBarcodeData(barcode);

return ['brand', 'desciption','manufacturer','title'].any((attribute) {
final attributeValue = result.data['product'][attribute];
if (attributeValue != null) {
final lowerCasedValue = attributeValue.toLowerCase();
final words = lowerCasedValue.split(' ');
return words.any((word) => _blacklist.contains(word));
return boycottList.data.any((word) => lowerCasedValue.contains(word));
}
return false;
});
Expand Down
19 changes: 19 additions & 0 deletions lib/data/sources/remote/boycott_data_source.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:dio/dio.dart';
import 'package:qataa/utils/constants/api_constants.dart';

class BoycottDataSource {
final dio = Dio()
..options.connectTimeout = const Duration(seconds: 10)
..options.receiveTimeout = const Duration(seconds: 10);

Future<Response> fetchBoycottList() async {
return await dio.get(
kBoycottListEndpoint,
options: Options(
validateStatus: (status) {
return status == 200;
},
),
);
}
}
2 changes: 0 additions & 2 deletions lib/presentation/views/scan_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import 'package:qataa/utils/screen_util.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

// TODO: Play Store ( Logo & Name )

class ScanScreen extends StatefulWidget {
const ScanScreen({super.key, required this.focusNodes, this.builder});
final focusNodes, builder;
Expand Down
28 changes: 14 additions & 14 deletions lib/presentation/widgets/bottom_sheet_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'package:get/get.dart';
import 'package:qataa/utils/constants/sizes.dart';

class BottomSheetContent extends StatelessWidget {
const BottomSheetContent({super.key, this.isBlacklisted,this.title, this.errorMessage});
const BottomSheetContent({super.key, this.isBoycotted,this.title, this.errorMessage});

final isBlacklisted, title, errorMessage;
final isBoycotted, title, errorMessage;

@override
Widget build(BuildContext context) {
Expand All @@ -25,26 +25,26 @@ class BottomSheetContent extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
isBlacklisted == null
isBoycotted == null
? 'assets/images/error.gif'
: isBlacklisted
? 'assets/images/blacklisted.gif'
: 'assets/images/not_blacklisted.gif',
: isBoycotted
? 'assets/images/boycotted.gif'
: 'assets/images/supported.gif',
height: kBottomSheetIconSize,
width: kBottomSheetIconSize),
Text(
isBlacklisted == null
isBoycotted == null
? title
: isBlacklisted
? 'blacklistedTitle'.tr
: 'notBlacklistedTitle'.tr,
: isBoycotted
? 'boycottedTitle'.tr
: 'supportedTitle'.tr,
style: Get.textTheme.headlineLarge),
Text(
isBlacklisted == null
isBoycotted == null
? errorMessage
: isBlacklisted
? 'blacklistSubtitle'.tr
: 'notBlacklistSubtitle'.tr,
: isBoycotted
? 'boycottSubtitle'.tr
: 'supportedSubtitle'.tr,
style: Get.textTheme.bodyLarge,
textAlign: TextAlign.center,
),
Expand Down
1 change: 1 addition & 0 deletions lib/utils/constants/api_constants.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const String kBarcodeEndpoint = 'https://barcodes1.p.rapidapi.com/';
const String kXRapidAPIKey = '90d54432aemshc7c7ea49bc042bbp15f633jsnab53706180b9';
const String kXRapidAPIHost = 'barcodes1.p.rapidapi.com';
const String kBoycottListEndpoint = 'https://raw.githubusercontent.com/Zied-Dahmani/qataa/main/assets/boycott_list.json';


0 comments on commit 19bfa38

Please sign in to comment.