Skip to content

Commit

Permalink
Merge branch 'ubuntu-flutter-community:main' into patch-6
Browse files Browse the repository at this point in the history
  • Loading branch information
Pompilos authored Nov 1, 2024
2 parents 3947842 + b9cb02d commit 679afb2
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 222 deletions.
4 changes: 2 additions & 2 deletions lib/common/logging.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';

void printMessageInDebugMode(String message) {
void printMessageInDebugMode(Object? object) {
if (kDebugMode) {
print(message);
print(object);
}
}
3 changes: 3 additions & 0 deletions lib/common/view/country_auto_complete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CountryAutoComplete extends StatelessWidget {
this.fillColor,
this.contentPadding,
this.suffixIcon,
this.autofocus = false,
});

final void Function(Country? country)? onSelected;
Expand All @@ -45,6 +46,7 @@ class CountryAutoComplete extends StatelessWidget {
final Color? fillColor;
final EdgeInsets? contentPadding;
final Widget? suffixIcon;
final bool autofocus;

@override
Widget build(BuildContext context) {
Expand All @@ -70,6 +72,7 @@ class CountryAutoComplete extends StatelessWidget {
final hintText =
'${context.l10n.search}: ${context.l10n.country}';
return TextField(
autofocus: autofocus,
maxLines: 1,
onTap: () {
textEditingController.selection = TextSelection(
Expand Down
3 changes: 3 additions & 0 deletions lib/common/view/language_autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LanguageAutoComplete extends StatelessWidget {
this.fillColor,
this.contentPadding,
this.suffixIcon,
this.autofocus = false,
});

final void Function(SimpleLanguage? language)? onSelected;
Expand All @@ -43,6 +44,7 @@ class LanguageAutoComplete extends StatelessWidget {
final Color? fillColor;
final EdgeInsets? contentPadding;
final Widget? suffixIcon;
final bool autofocus;

@override
Widget build(BuildContext context) {
Expand All @@ -68,6 +70,7 @@ class LanguageAutoComplete extends StatelessWidget {
final hintText =
'${context.l10n.search}: ${context.l10n.language}';
return TextField(
autofocus: autofocus,
maxLines: 1,
onTap: () {
textEditingController.selection = TextSelection(
Expand Down
4 changes: 4 additions & 0 deletions lib/common/view/search_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SearchInput extends StatefulWidget {
this.onChanged,
this.hintText,
this.suffixIcon,
this.prefixIcon,
this.autoFocus = true,
});
final String? text;
Expand All @@ -20,6 +21,7 @@ class SearchInput extends StatefulWidget {
final void Function(String)? onChanged;
final String? hintText;
final Widget? suffixIcon;
final Widget? prefixIcon;
final bool autoFocus;

@override
Expand Down Expand Up @@ -73,11 +75,13 @@ class _SearchInputState extends State<SearchInput> {
theme: theme,
hintText: widget.hintText,
suffixIcon: widget.suffixIcon,
prefixIcon: widget.prefixIcon,
)
: createMaterialDecoration(
colorScheme: theme.colorScheme,
hintText: widget.hintText,
suffixIcon: widget.suffixIcon,
prefixIcon: widget.prefixIcon,
),
),
);
Expand Down
4 changes: 4 additions & 0 deletions lib/common/view/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ InputDecoration createMaterialDecoration({
EdgeInsets? contentPadding,
String? hintText,
Widget? suffixIcon,
Widget? prefixIcon,
}) {
final outlineInputBorder = border ??
OutlineInputBorder(
borderRadius: BorderRadius.circular(100),
borderSide: BorderSide(width: 1, color: colorScheme.outline),
);
return InputDecoration(
prefixIcon: prefixIcon,
suffixIcon: suffixIcon,
suffixIconConstraints: const BoxConstraints(
maxWidth: 200,
Expand Down Expand Up @@ -162,6 +164,7 @@ InputDecoration createYaruDecoration({
String? hintText,
OutlineInputBorder? border,
Widget? suffixIcon,
Widget? prefixIcon,
}) {
final fill = theme.inputDecorationTheme.fillColor;

Expand All @@ -172,6 +175,7 @@ InputDecoration createYaruDecoration({
);

return InputDecoration(
prefixIcon: prefixIcon,
suffixIcon: Center(
widthFactor: 1,
child: suffixIcon,
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
"contributors": "Collaboratori",
"version": "Versione",
"theme": "Tema",
"useMoreAnimationsTitle": "Usa più animazioni",
"useMoreAnimationsDescription": "Ciò aumenterà leggermente l'uso della CPU, che potrebbe essere non ottimale con hardware non aggiornato.",
"license": "Licenza",
"dependencies": "Dipendenze",
"light": "Chiaro",
Expand Down
3 changes: 2 additions & 1 deletion lib/library/library_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:safe_change_notifier/safe_change_notifier.dart';

import '../common/data/audio.dart';
import '../common/logging.dart';
import '../common/view/back_gesture.dart';
import '../constants.dart';
import 'library_service.dart';

Expand Down Expand Up @@ -202,7 +203,7 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
await _masterNavigatorKey.currentState?.pushNamed(pageId);
} else if (builder != null) {
final materialPageRoute = MaterialPageRoute(
builder: builder,
builder: (context) => BackGesture(child: builder(context)),
maintainState: maintainState,
settings: RouteSettings(
name: pageId,
Expand Down
6 changes: 6 additions & 0 deletions lib/patch_notes/patch_notes_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class _PatchNotesDialogState extends State<PatchNotesDialog> {
future: _markdown,
builder: (context, snapshot) => snapshot.hasData
? MarkdownBody(
onTapLink: (text, href, title) {
if (href == null) return;
final uri = Uri.tryParse(href);
if (uri == null) return;
launchUrl(uri);
},
data: snapshot.data!,
)
: const Center(
Expand Down
4 changes: 3 additions & 1 deletion lib/podcasts/podcast_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:podcast_search/podcast_search.dart';

import '../common/data/audio.dart';
import '../common/data/podcast_genre.dart';
import '../common/logging.dart';
import '../common/view/audio_filter.dart';
import '../common/view/languages.dart';
import '../library/library_service.dart';
Expand Down Expand Up @@ -70,7 +71,8 @@ class PodcastService {
limit: limit,
);
}
} catch (_) {
} catch (e) {
printMessageInDebugMode(e);
return _searchResult;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/search/search_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ class SearchModel extends SafeChangeNotifier {
}

List<PodcastGenre> getPodcastGenres(bool usePodcastIndex) {
final notSelected =
PodcastGenre.values.where((g) => g != podcastGenre).toList();
PodcastGenre.values.where((g) => g != podcastGenre).toList();

final list = [podcastGenre, ...notSelected];
const list = PodcastGenre.values;

return usePodcastIndex
? list.where((e) => !e.name.contains('XXXITunesOnly')).toList()
Expand Down
2 changes: 1 addition & 1 deletion lib/search/view/audio_type_filter_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AudioTypeFilterButton extends StatelessWidget with WatchItMixin {
onSelected: (v) async {
searchModel
..setAudioType(v)
..search();
..search(clear: true);
},
itemBuilder: (context) => AudioType.values
.map(
Expand Down
171 changes: 171 additions & 0 deletions lib/search/view/podcast_search_input_prefix.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import 'package:flutter/material.dart';
import 'package:podcast_search/podcast_search.dart';
import 'package:watch_it/watch_it.dart';

import '../../common/view/country_auto_complete.dart';
import '../../common/view/icons.dart';
import '../../common/view/language_autocomplete.dart';
import '../../common/view/theme.dart';
import '../../extensions/build_context_x.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../../settings/settings_model.dart';
import '../search_model.dart';

class PodcastSearchInputPrefix extends StatelessWidget with WatchItMixin {
const PodcastSearchInputPrefix({
super.key,
});

@override
Widget build(BuildContext context) {
final usePodcastIndex =
watchPropertyValue((SettingsModel m) => m.usePodcastIndex);
final l10n = context.l10n;
return IconButton(
tooltip: usePodcastIndex ? l10n.language : l10n.country,
onPressed: () => showDialog(
context: context,
builder: (context) => const LocationFilterDialog(),
),
icon: Icon(Iconz.globe),
);
}
}

class LocationFilterDialog extends StatelessWidget {
const LocationFilterDialog({
super.key,
});

@override
Widget build(BuildContext context) {
return AlertDialog(
titlePadding: EdgeInsets.zero,
contentPadding: const EdgeInsets.all(20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
content: const LocationFilter(),
);
}
}

class LocationFilter extends StatelessWidget with WatchItMixin {
const LocationFilter({super.key});

@override
Widget build(BuildContext context) {
final libraryModel = di<LibraryModel>();
final theme = context.theme;
final searchModel = di<SearchModel>();
watchPropertyValue((LibraryModel m) => m.favLanguagesLength);
watchPropertyValue((LibraryModel m) => m.favCountriesLength);
final country = watchPropertyValue((SearchModel m) => m.country);

void setCountry(Country? country) {
searchModel.setCountry(country);
if (country?.code != null) {
libraryModel.setLastCountryCode(country!.code);
}
}

final usePodcastIndex =
watchPropertyValue((SettingsModel m) => m.usePodcastIndex);
watchPropertyValue((LibraryModel m) => m.favLanguagesLength);
watchPropertyValue((LibraryModel m) => m.favCountriesLength);
final favLanguageCodes =
watchPropertyValue((LibraryModel m) => m.favLanguageCodes);

final language = watchPropertyValue((SearchModel m) => m.language);

final fillColor = theme.chipTheme.selectedColor;

const width = 150.0;
final height = chipHeight;
var outlineInputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(100),
borderSide: yaruStyled
? BorderSide.none
: BorderSide(
color: theme.colorScheme.outline,
width: 1.3,
strokeAlign: 1,
),
);
final style = theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
);

return usePodcastIndex
? LanguageAutoComplete(
autofocus: true,
contentPadding: countryPillPadding,
fillColor: language != null
? fillColor
: yaruStyled
? theme.dividerColor
: null,
filled: language != null,
border: outlineInputBorder,
style: style,
isDense: true,
width: width,
height: height,
value: language,
favs: favLanguageCodes,
addFav: (language) {
if (language?.isoCode == null) return;
libraryModel.addFavLanguageCode(language!.isoCode);
},
removeFav: (language) {
if (language?.isoCode == null) return;
libraryModel.removeFavLanguageCode(language!.isoCode);
},
onSelected: (language) {
Navigator.of(context).pop();
searchModel.setLanguage(language);
if (language?.isoCode != null) {
libraryModel.setLastLanguage(language!.isoCode);
}
searchModel.search();
},
)
: CountryAutoComplete(
autofocus: true,
contentPadding: countryPillPadding,
fillColor: fillColor,
filled: true,
border: outlineInputBorder,
style: style,
isDense: true,
width: width,
height: height,
countries: [
...[
...Country.values,
].where(
(e) => libraryModel.favCountryCodes.contains(e.code) == true,
),
...[...Country.values].where(
(e) => libraryModel.favCountryCodes.contains(e.code) == false,
),
]..remove(Country.none),
onSelected: (country) {
Navigator.of(context).pop();
setCountry(country);
searchModel.search();
},
value: country,
addFav: (v) {
if (country?.code == null) return;
libraryModel.addFavCountryCode(v!.code);
},
removeFav: (v) {
if (country?.code == null) return;
libraryModel.removeFavCountryCode(v!.code);
},
favs: libraryModel.favCountryCodes,
);
}
}
9 changes: 3 additions & 6 deletions lib/search/view/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ class SearchPage extends StatelessWidget with WatchItMixin {
builder: (context, constraints) {
return NotificationListener<UserScrollNotification>(
onNotification: (notification) {
// TODO(#926): improve radio search limit increase by not overwriting the search results
// disabled for radio until then
if (notification.direction == ScrollDirection.reverse &&
audioType == AudioType.podcast) {
if (notification.metrics.axisDirection == AxisDirection.down &&
notification.direction == ScrollDirection.reverse &&
audioType != AudioType.local) {
di<SearchModel>()
..incrementLimit(8)
..search();
Expand All @@ -74,9 +73,7 @@ class SearchPage extends StatelessWidget with WatchItMixin {
getAdaptiveHorizontalPadding(constraints: constraints)
.copyWith(
bottom: filterPanelPadding.bottom,
left: filterPanelPadding.left,
top: filterPanelPadding.top,
right: filterPanelPadding.right,
),
onStretchTrigger: () async {
WidgetsBinding.instance
Expand Down
Loading

0 comments on commit 679afb2

Please sign in to comment.