Skip to content

Commit

Permalink
feat: load more podcasts on scroll, update deps (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Sep 18, 2024
1 parent 8938026 commit 741d090
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 79 deletions.
4 changes: 2 additions & 2 deletions lib/extensions/country_x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ extension CountryX on Country {
Country.colombia => l10n.regionColombia,
Country.comoros => l10n.regionComoros,
Country.congo => l10n.regionCongo,
Country.congoDemocraticRepublicof =>
Country.congoDemocraticRepublicOf =>
l10n.regionCongodemocraticrepublicof,
Country.cookIslands => l10n.regionCookislands,
Country.costarica => l10n.regionCostarica,
Country.costaRica => l10n.regionCostarica,
Country.coteDivoire => l10n.regionCotedivoire,
Country.croatia => l10n.regionCroatia,
Country.cuba => l10n.regionCuba,
Expand Down
18 changes: 11 additions & 7 deletions lib/podcasts/podcast_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class PodcastService {
}
}

String? _previousQuery;
Future<SearchResult?> search({
String? searchQuery,
PodcastGenre podcastGenre = PodcastGenre.all,
Expand All @@ -49,7 +50,6 @@ class PodcastService {
int limit = 10,
}) async {
SearchResult? result;
String? error;
try {
if (searchQuery == null || searchQuery.isEmpty == true) {
result = await _search?.charts(
Expand All @@ -70,16 +70,20 @@ class PodcastService {
limit: limit,
);
}
} catch (e) {
error = e.toString();
} catch (_) {
return _searchResult;
}

if (result != null && result.successful) {
if (result != null &&
result.successful &&
(searchQuery == null ||
_previousQuery != searchQuery ||
(_previousQuery == searchQuery &&
_searchResult?.items.isNotEmpty == true))) {
_searchResult = result;
} else {
_searchResult =
SearchResult.fromError(lastError: error ?? 'Something went wrong');
}
_previousQuery = searchQuery;

return _searchResult;
}

Expand Down
32 changes: 15 additions & 17 deletions lib/podcasts/podcast_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,27 @@ Future<List<Audio>> findEpisodes({
String? itemImageUrl,
String? genre,
}) async {
final episodes = <Audio>[];
final Podcast? podcast = await compute(loadPodcast, feedUrl);
final episodes = podcast?.episodes
.where((e) => e.contentUrl != null)
.map(
(e) => Audio.fromPodcast(
episode: e,
podcast: podcast,
itemImageUrl: itemImageUrl,
genre: genre,
),
)
.toList() ??
<Audio>[];

if (podcast?.episodes.isNotEmpty == true) {
for (var episode in podcast?.episodes ?? []) {
if (episode.contentUrl != null) {
final audio = Audio.fromPodcast(
episode: episode,
podcast: podcast,
itemImageUrl: itemImageUrl,
genre: genre,
);
episodes.add(audio);
}
}
}
final sortedEpisodes = episodes.toList();
sortListByAudioFilter(
audioFilter: AudioFilter.year,
audios: sortedEpisodes,
audios: episodes,
descending: true,
);
return List<Audio>.from(sortedEpisodes);

return episodes;
}

Future<Podcast?> loadPodcast(String url) async {
Expand Down
4 changes: 3 additions & 1 deletion lib/search/search_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class SearchModel extends SafeChangeNotifier {
String? get searchQuery => _searchQuery;
void setSearchQuery(String? value) {
if (value == _searchQuery) return;
_podcastLimit = _podcastDefaultLimit;
_searchQuery = value;
notifyListeners();
}
Expand Down Expand Up @@ -142,7 +143,8 @@ class SearchModel extends SafeChangeNotifier {
return _localAudioService.search(_searchQuery);
}

int _podcastLimit = 30;
static const _podcastDefaultLimit = 32;
int _podcastLimit = _podcastDefaultLimit;
void incrementPodcastLimit(int value) => _podcastLimit += value;

bool loading = false;
Expand Down
76 changes: 45 additions & 31 deletions lib/search/view/search_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:watch_it/watch_it.dart';
import 'package:yaru/theme.dart';

Expand Down Expand Up @@ -54,38 +55,51 @@ class SearchPage extends StatelessWidget with WatchItMixin {
),
body: LayoutBuilder(
builder: (context, constraints) {
return CustomScrollView(
slivers: [
SliverFilterAppBar(
padding: getAdaptiveHorizontalPadding(constraints: constraints)
.copyWith(
bottom: filterPanelPadding.bottom,
left: filterPanelPadding.left,
top: filterPanelPadding.top,
right: filterPanelPadding.right,
return NotificationListener<UserScrollNotification>(
onNotification: (notification) {
if (notification.direction == ScrollDirection.reverse &&
audioType == AudioType.podcast) {
di<SearchModel>()
..incrementPodcastLimit(8)
..search();
}
return true;
},
child: CustomScrollView(
slivers: [
SliverFilterAppBar(
padding:
getAdaptiveHorizontalPadding(constraints: constraints)
.copyWith(
bottom: filterPanelPadding.bottom,
left: filterPanelPadding.left,
top: filterPanelPadding.top,
right: filterPanelPadding.right,
),
onStretchTrigger: () async {
WidgetsBinding.instance
.addPostFrameCallback((timeStamp) async {
if (context.mounted) {
return di<SearchModel>().search();
}
});
},
title: switch (audioType) {
AudioType.podcast => const SliverPodcastFilterBar(),
_ => const SliverSearchTypeFilterBar(),
},
),
onStretchTrigger: () async {
WidgetsBinding.instance
.addPostFrameCallback((timeStamp) async {
if (context.mounted) {
return di<SearchModel>().search();
}
});
},
title: switch (audioType) {
AudioType.podcast => const SliverPodcastFilterBar(),
_ => const SliverSearchTypeFilterBar(),
},
),
SliverPadding(
padding: getAdaptiveHorizontalPadding(constraints: constraints),
sliver: switch (audioType) {
AudioType.radio => const SliverRadioSearchResults(),
AudioType.podcast => const SliverPodcastSearchResults(),
AudioType.local => const SliverLocalSearchResult(),
},
),
],
SliverPadding(
padding:
getAdaptiveHorizontalPadding(constraints: constraints),
sliver: switch (audioType) {
AudioType.radio => const SliverRadioSearchResults(),
AudioType.podcast => const SliverPodcastSearchResults(),
AudioType.local => const SliverLocalSearchResult(),
},
),
],
),
);
},
),
Expand Down
31 changes: 19 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ packages:
dependency: "direct main"
description:
name: dio
sha256: "0dfb6b6a1979dac1c1245e17cef824d7b452ea29bd33d3467269f9bef3715fb0"
sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260"
url: "https://pub.dev"
source: hosted
version: "5.6.0"
version: "5.7.0"
dio_web_adapter:
dependency: transitive
description:
Expand Down Expand Up @@ -643,6 +643,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
gsettings:
dependency: transitive
description:
name: gsettings
sha256: "1b0ce661f5436d2db1e51f3c4295a49849f03d304003a7ba177d01e3a858249c"
url: "https://pub.dev"
source: hosted
version: "0.2.8"
gtk:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1122,10 +1130,10 @@ packages:
dependency: "direct main"
description:
name: podcast_search
sha256: ab3a98d2bb7a593cee61351fae17900d3cc6e23e21638d7ae16963bb11cf9693
sha256: c2ca2529a7f561827cc62db6c4fba6cade0249936455912a902688125c90bd5c
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.3"
pointycastle:
dependency: transitive
description:
Expand Down Expand Up @@ -1202,10 +1210,10 @@ packages:
dependency: "direct main"
description:
name: safe_change_notifier
sha256: "8d0645ec2706f580912c38de488439ddb491be48247826927b7bc2e54ea8f7af"
sha256: e7cce266bfede647355866fa3bd054feda57c220d2383f4203f28d4dcdb3b82e
url: "https://pub.dev"
source: hosted
version: "0.3.2"
version: "0.4.0"
safe_local_storage:
dependency: transitive
description:
Expand Down Expand Up @@ -1758,12 +1766,11 @@ packages:
yaru:
dependency: "direct main"
description:
path: "."
ref: "8a16a69d5f9ea7b0154035f34c0863c987a98497"
resolved-ref: "8a16a69d5f9ea7b0154035f34c0863c987a98497"
url: "https://github.com/ubuntu/yaru.dart"
source: git
version: "5.1.0"
name: yaru
sha256: "29024f7f85ec959bab300eb5170f5e6dd48364027875b2098bf966a7c64b9ca4"
url: "https://pub.dev"
source: hosted
version: "5.2.0"
yaru_window:
dependency: "direct main"
description:
Expand Down
14 changes: 5 additions & 9 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies:
handy_window: ^0.4.0
html: ^0.15.4
http: ^1.2.1
intl: ^0.18.0
intl: ^0.19.0
m3u_parser_nullsafe: ^1.0.3
media_kit: ^1.1.10+1
media_kit_libs_video: ^1.0.4
Expand All @@ -62,10 +62,10 @@ dependencies:
url: https://github.com/ubuntu-flutter-community/phoenix_theme
ref: fe7b369cdf03a15c735c866584a251da68f3a716
pls: ^1.1.0
podcast_search: ^0.7.2
podcast_search: ^0.7.3
radio_browser_api: ^2.0.0
reorderableitemsview: ^2.0.1
safe_change_notifier: ^0.3.2
safe_change_notifier: ^0.4.0
scroll_to_index: ^3.0.1
shared_preferences: ^2.3.1
shimmer: ^3.0.0
Expand All @@ -77,10 +77,7 @@ dependencies:
win32: ^5.5.4
window_manager: ^0.3.9
xdg_directories: ^1.0.4
yaru:
git:
url: https://github.com/ubuntu/yaru.dart
ref: 8a16a69d5f9ea7b0154035f34c0863c987a98497
yaru: ^5.2.0
yaru_window: ^0.2.1
yaru_window_linux: ^0.2.0

Expand All @@ -100,8 +97,7 @@ flutter:
- assets/images/tray_icon.png
- CHANGELOG.md

dependency_overrides:
intl: 0.19.0
dependency_overrides:
media_kit_native_event_loop:
git:
url: https://github.com/media-kit/media-kit
Expand Down

0 comments on commit 741d090

Please sign in to comment.