Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Fixed: #269 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanvandeperre97 authored Sep 15, 2020
1 parent 544558c commit b4b6e4a
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Color : colors are not pastel anymore
- UI : fixed too big screens
- Pull to refresh : messages are now translated
- Share contact : User can now have contacts without a name
- Accessibility : text size can't be modified by the phone settings anymore

### Security
Expand Down
58 changes: 26 additions & 32 deletions lib/pages/share_one.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:MobileOne/providers/share_provider.dart';
import 'package:MobileOne/services/analytics_services.dart';
import 'package:MobileOne/services/color_service.dart';
import 'package:MobileOne/services/messaging_service.dart';
import 'package:MobileOne/services/share_service.dart';
import 'package:MobileOne/services/user_service.dart';
import 'package:MobileOne/utility/arguments.dart';
import 'package:MobileOne/widgets/widget_share_contact.dart';
Expand All @@ -27,6 +28,7 @@ class ShareStateOneState extends State<ShareOne> {
var newUuid;
final _myController = TextEditingController();
var shareProvider = GetIt.I.get<ShareProvider>();
var shareService = GetIt.I.get<ShareService>();
var _colorsApp = GetIt.I.get<ColorService>();
String emailRegexp =
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+";
Expand Down Expand Up @@ -67,18 +69,10 @@ class ShareStateOneState extends State<ShareOne> {
}

filterContact() {
List<Contact> _contacts = [];
_contacts.addAll(contacts);
if (_myController.text.isNotEmpty) {
_contacts.retainWhere((contact) {
String searchTerm = _myController.text.toLowerCase();
String contactName = contact.displayName.toLowerCase();
return contactName.contains(searchTerm);
});
setState(() {
contactsFilter = _contacts;
});
}
setState(() {
contactsFilter =
shareService.filterContacts(contacts, _myController.text);
});
}

Widget build(BuildContext context) {
Expand All @@ -87,23 +81,25 @@ class ShareStateOneState extends State<ShareOne> {
return Scaffold(
resizeToAvoidBottomPadding: false,
backgroundColor: _colorsApp.colorTheme,
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
header(context),
(_argsShare.isOnlyOneStep == false)
? headerSteps(context)
: Container(height: MediaQuery.of(context).size.height * 0.1),
searchContact(context),
searchNewContact(context, _argsShare.previousList),
loader == false
? Center(
child: CircularProgressIndicator(),
)
: Container(
height: MediaQuery.of(context).size.height * 0.64,
child: buildListView(isSearching, _argsShare.previousList)),
],
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
header(context),
(_argsShare.isOnlyOneStep == false)
? headerSteps(context)
: Container(height: MediaQuery.of(context).size.height * 0.1),
searchContact(context),
searchNewContact(context, _argsShare.previousList),
loader == false
? Center(
child: CircularProgressIndicator(),
)
: Container(
height: MediaQuery.of(context).size.height * 0.64,
child: buildListView(isSearching, _argsShare.previousList)),
],
),
),
);
}
Expand Down Expand Up @@ -211,9 +207,7 @@ class ShareStateOneState extends State<ShareOne> {
child: (_myController.text.length > 2)
? WidgetShareContact(
name: _myController.text, email: _myController.text)
: Container(
height: 1,
),
: Container(),
),
),
);
Expand Down
18 changes: 18 additions & 0 deletions lib/services/share_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter/material.dart';

class ShareService with ChangeNotifier {
Expand All @@ -11,4 +12,21 @@ class ShareService with ChangeNotifier {
_number = number;
notifyListeners();
}

List<Contact> filterContacts(List<Contact> _contactsList, String text) {
List<Contact> _filteredContactsList = [];
_filteredContactsList.addAll(_contactsList);
if (text != null) {
_filteredContactsList.retainWhere((contact) {
if (contact.displayName != null) {
String searchTerm = text.toLowerCase();
String contactName = contact.displayName.toLowerCase();
return contactName.contains(searchTerm);
} else {
return false;
}
});
}
return _filteredContactsList;
}
}
41 changes: 29 additions & 12 deletions lib/widgets/widget_share_contact.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';
import 'dart:math';
import 'package:MobileOne/localization/localization.dart';
import 'package:MobileOne/services/color_service.dart';
import 'package:MobileOne/utility/colors.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -29,10 +30,17 @@ class WidgetShareContactState extends State<WidgetShareContact> {
backgroundImage: MemoryImage(widget.avatar),
)
: (widget.email.length > 2)
? CircleAvatar(
backgroundColor: Colors
.primaries[Random().nextInt(Colors.primaries.length)],
child: Text(widget.name.substring(0, 2)))
? (widget.name != null)
? CircleAvatar(
backgroundColor: Colors.primaries[
Random().nextInt(Colors.primaries.length)],
child: Text(widget.name.substring(0, 2)))
: CircleAvatar(
backgroundColor: Colors.primaries[
Random().nextInt(Colors.primaries.length)],
child: Text(
getString(context, "undefined_contact_name")
.substring(0, 2)))
: CircleAvatar(
backgroundColor: Colors
.primaries[Random().nextInt(Colors.primaries.length)],
Expand All @@ -44,14 +52,23 @@ class WidgetShareContactState extends State<WidgetShareContact> {
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text(
widget.name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: WHITE,
),
),
(widget.name != null)
? Text(
widget.name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: WHITE,
),
)
: Text(
getString(context, "undefined_contact_name"),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: WHITE,
),
),
Text(
widget.email,
style: TextStyle(
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,6 @@
"nobody": "nobody",
"refresh": "Loading...",
"refresh_complete": "Refresh complete",
"refresh_failed": "Refresh failed"
"refresh_failed": "Refresh failed",
"undefined_contact_name": "Undefined name"
}
3 changes: 2 additions & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,6 @@
"nobody": "personne",
"refresh": "Chargement...",
"refresh_complete": "Rafraichissement réussi",
"refresh_failed": "Rafraichissement échoué"
"refresh_failed": "Rafraichissement échoué",
"undefined_contact_name": "Nom non défini"
}
29 changes: 29 additions & 0 deletions test/filter_contacts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:MobileOne/services/share_service.dart';
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test("Filter contacts", () {
//Given

final service = ShareService();
List<Contact> list = [
Contact(displayName: "test", emails: {Item(value: "test@test.test")}),
Contact(displayName: "second test"),
Contact(),
Contact(emails: {Item(value: "test@test.test")}),
];

//When
List<Contact> result = service.filterContacts(list, "second");

//Then
expect(result == null, false);
expect(result.isNotEmpty, true);
expect(
result.singleWhere((element) => element.displayName == "second test") !=
null,
true);
expect(result.length, 1);
});
}
61 changes: 61 additions & 0 deletions test/share_contact_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:MobileOne/localization/supported.dart';
import 'package:MobileOne/widgets/widget_share_contact.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
setSupportedLocales([Locale('fr', 'FR')]);

group('Share contact tests', () {
test('Share contact widget should work with a name', () {
//GIVEN

//WHEN
WidgetShareContact _widget = WidgetShareContact(
name: "test",
);

//THEN
expect(_widget != null, true);
expect(_widget.name, "test");
});

test('Share contact widget should work with an email', () {
//GIVEN

//WHEN
WidgetShareContact _widget = WidgetShareContact(
email: "test@test.test",
);

//THEN
expect(_widget != null, true);
expect(_widget.email, "test@test.test");
});

test('Share contact widget should work with an email and a name', () {
//GIVEN

//WHEN
WidgetShareContact _widget = WidgetShareContact(
email: "test@test.test",
name: "test",
);

//THEN
expect(_widget != null, true);
expect(_widget.email, "test@test.test");
expect(_widget.name, "test");
});

test('Share contact widget should work without an email and a name', () {
//GIVEN

//WHEN
WidgetShareContact _widget = WidgetShareContact();

//THEN
expect(_widget != null, true);
});
});
}

0 comments on commit b4b6e4a

Please sign in to comment.