-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from EgidioCaprino/search-filters
add search filters with sorting option
- Loading branch information
Showing
6 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
enum SearchSortBy { | ||
relevance, | ||
rating, | ||
upload_date, | ||
view_count; | ||
date, | ||
views; | ||
|
||
String getLable(AppLocalizations locals) { | ||
return switch(this) { | ||
(SearchSortBy.relevance) => locals.searchSortRelevance, | ||
(SearchSortBy.rating) => locals.searchSortRating, | ||
(SearchSortBy.date) => locals.searchSortUploadDate, | ||
(SearchSortBy.views) => locals.searchSortViewCount, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:invidious/search/models/search_sort_by.dart'; | ||
|
||
const defaultSearchSortBy = SearchSortBy.relevance; | ||
|
||
class SearchFiltersButton extends StatelessWidget { | ||
final SearchSortBy initialSearchSortBy; | ||
final Function(SearchSortBy) callback; | ||
|
||
const SearchFiltersButton({ | ||
super.key, | ||
required this.initialSearchSortBy, | ||
required this.callback, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final locals = AppLocalizations.of(context)!; | ||
return IconButton( | ||
onPressed: () { | ||
showDialog( | ||
context: context, | ||
barrierDismissible: false, | ||
builder: (BuildContext context) { | ||
SearchSortBy selectedSearchSortBy = initialSearchSortBy; | ||
return AlertDialog( | ||
content: StatefulBuilder( | ||
builder: (BuildContext context, StateSetter setState) { | ||
onChanged(SearchSortBy? newSearchSortBy) { | ||
setState(() => selectedSearchSortBy = | ||
newSearchSortBy ?? defaultSearchSortBy); | ||
} | ||
|
||
return SingleChildScrollView( | ||
child: ListBody(children: <Widget>[ | ||
Text(locals.searchSortBy), | ||
...SearchSortBy.values.map((value) { | ||
return ListTile( | ||
title: Text(value.getLable(locals)), | ||
leading: Radio<SearchSortBy>( | ||
value: value, | ||
groupValue: selectedSearchSortBy, | ||
onChanged: onChanged, | ||
), | ||
); | ||
}), | ||
]), | ||
); | ||
}, | ||
), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: Text(locals.cancel), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
TextButton( | ||
child: Text(locals.ok), | ||
onPressed: () { | ||
callback(selectedSearchSortBy); | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
}, | ||
icon: const Icon(Icons.filter_list_alt), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters