Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 47 additions & 20 deletions lib/screens/downloads_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _DownloadsScreenState extends State<DownloadsScreen> {
// Variables related to the filter bar in the appbar
final TextEditingController _filterController = TextEditingController();
List<DownloadedCard> _filteredDownloads = [];
bool _useAndFilter = true;

@override
void initState() {
Expand All @@ -48,12 +49,21 @@ class _DownloadsScreenState extends State<DownloadsScreen> {
if (query.isEmpty) {
_filteredDownloads = List.from(_downloadedArticles);
} else {
List<String> keywords = query.toLowerCase().split(' ');

_filteredDownloads = _downloadedArticles.where((article) {
final title = article.publicationCard.title.toLowerCase();
final journalTitle =
article.publicationCard.journalTitle.toLowerCase();
return title.contains(query.toLowerCase()) ||
journalTitle.contains(query.toLowerCase());
bool matchesAnyField(String word) {
return article.publicationCard.title.toLowerCase().contains(word) ||
article.publicationCard.journalTitle
.toLowerCase()
.contains(word);
}

if (_useAndFilter) {
return keywords.every(matchesAnyField); // AND logic
} else {
return keywords.any(matchesAnyField); // OR logic
}
}).toList();
}
});
Expand Down Expand Up @@ -82,23 +92,40 @@ class _DownloadsScreenState extends State<DownloadsScreen> {
prefixIcon: Icon(Icons.search),
filled: true,
fillColor: Color.fromARGB(31, 148, 147, 147),
suffixIcon: PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
suffixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
setState(() {
_useAndFilter = !_useAndFilter;
_filterDownloads(_filterController.text);
});
},
child: Text(
_useAndFilter ? 'AND' : 'OR',
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text(AppLocalizations.of(context)!.sortorder),
),
PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title:
Text(AppLocalizations.of(context)!.sortorder),
),
),
],
),
],
)),
Expand Down
88 changes: 55 additions & 33 deletions lib/screens/favorites_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class _FavoritesScreenState extends State<FavoritesScreen> {
List<PublicationCard> _allFavorites = [];
List<PublicationCard> _filteredFavorites = [];

bool _useAndFilter = true;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -64,24 +66,28 @@ class _FavoritesScreenState extends State<FavoritesScreen> {
if (query.isEmpty) {
_filteredFavorites = List.from(_allFavorites);
} else {
_filteredFavorites = _allFavorites
.where((publication) =>
publication.title.toLowerCase().contains(query.toLowerCase()) ||
publication.journalTitle
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.abstract
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.licenseName
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.authors.any((author) => author.family
.toLowerCase()
.contains(query.toLowerCase())) ||
publication.authors.any((author) =>
author.given.toLowerCase().contains(query.toLowerCase())))
.toList();
List<String> keywords = query.toLowerCase().split(' ');

_filteredFavorites = _allFavorites.where((publication) {
bool matchesAnyField(String word, PublicationCard pub) {
return pub.title.toLowerCase().contains(word) ||
pub.journalTitle.toLowerCase().contains(word) ||
pub.abstract.toLowerCase().contains(word) ||
pub.licenseName.toLowerCase().contains(word) ||
pub.authors.any(
(author) => author.family.toLowerCase().contains(word)) ||
pub.authors
.any((author) => author.given.toLowerCase().contains(word));
}

if (_useAndFilter) {
return keywords.every(
(word) => matchesAnyField(word, publication)); // AND logic
} else {
return keywords
.any((word) => matchesAnyField(word, publication)); // OR logic
}
}).toList();
}
_filteredFavorites = _sortFavorites(_filteredFavorites);
});
Expand Down Expand Up @@ -110,23 +116,39 @@ class _FavoritesScreenState extends State<FavoritesScreen> {
prefixIcon: Icon(Icons.search),
filled: true,
fillColor: Color.fromARGB(31, 148, 147, 147),
suffixIcon: PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
suffixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
setState(() {
_useAndFilter = !_useAndFilter;
_filterFeed(_filterController.text);
});
},
child: Text(
_useAndFilter ? 'AND' : 'OR',
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text(AppLocalizations.of(context)!.sortorder),
),
PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text(AppLocalizations.of(context)!.sortorder),
),
),
],
),
],
),
Expand Down
101 changes: 61 additions & 40 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _HomeScreenState extends State<HomeScreen> {

List<Map<String, dynamic>> savedQueries = [];
bool _feedLoaded = false; // Needed to avoid conflicts wih onAbstractChanged
bool _useAndFilter = true;

@override
void initState() {
Expand Down Expand Up @@ -165,24 +166,28 @@ class _HomeScreenState extends State<HomeScreen> {
if (query.isEmpty) {
_filteredFeed = List.from(_allFeed);
} else {
_filteredFeed = _allFeed
.where((publication) =>
publication.title.toLowerCase().contains(query.toLowerCase()) ||
publication.journalTitle
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.abstract
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.licenseName
.toLowerCase()
.contains(query.toLowerCase()) ||
publication.authors.any((author) => author.family
.toLowerCase()
.contains(query.toLowerCase())) ||
publication.authors.any((author) =>
author.given.toLowerCase().contains(query.toLowerCase())))
.toList();
List<String> keywords = query.toLowerCase().split(' ');

_filteredFeed = _allFeed.where((publication) {
bool matchesAnyField(String word, PublicationCard pub) {
return pub.title.toLowerCase().contains(word) ||
pub.journalTitle.toLowerCase().contains(word) ||
pub.abstract.toLowerCase().contains(word) ||
pub.licenseName.toLowerCase().contains(word) ||
pub.authors.any(
(author) => author.family.toLowerCase().contains(word)) ||
pub.authors
.any((author) => author.given.toLowerCase().contains(word));
}

if (_useAndFilter) {
return keywords.every(
(word) => matchesAnyField(word, publication)); // AND logic
} else {
return keywords
.any((word) => matchesAnyField(word, publication)); // OR logic
}
}).toList();
}
_sortFeed();
});
Expand Down Expand Up @@ -269,30 +274,46 @@ class _HomeScreenState extends State<HomeScreen> {
prefixIcon: Icon(Icons.search),
filled: true,
fillColor: Color.fromARGB(31, 148, 147, 147),
suffixIcon: PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.settings_outlined),
title: Text(AppLocalizations.of(context)!.settings),
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
suffixIcon: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
setState(() {
_useAndFilter = !_useAndFilter;
_filterFeed(_filterController.text);
});
},
child: Text(
_useAndFilter ? 'AND' : 'OR',
),
),
PopupMenuItem<int>(
value: 2,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text(AppLocalizations.of(context)!.sortorder),
),
PopupMenuButton<int>(
icon: Icon(Icons.more_vert),
onSelected: (item) => handleMenuButton(item),
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: ListTile(
leading: Icon(Icons.settings_outlined),
title: Text(AppLocalizations.of(context)!.settings),
),
),
PopupMenuItem<int>(
value: 1,
child: ListTile(
leading: Icon(Icons.sort),
title: Text(AppLocalizations.of(context)!.sortby),
),
),
PopupMenuItem<int>(
value: 2,
child: ListTile(
leading: Icon(Icons.sort_by_alpha),
title: Text(AppLocalizations.of(context)!.sortorder),
),
),
],
),
],
),
Expand Down