Skip to content

Commit

Permalink
fix: radiosearch empty on initial search swap from podcasts, add back…
Browse files Browse the repository at this point in the history
… radio search -> StationPage routing (#989)
  • Loading branch information
Feichtmeier authored Oct 30, 2024
1 parent 09d6582 commit 27ab963
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 49 deletions.
22 changes: 17 additions & 5 deletions lib/common/view/audio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AudioTile extends StatefulWidget with WatchItStatefulWidgetMixin {
required this.audioPageType,
required this.showLeading,
this.selectedColor,
this.onTitleTap,
});

final String pageId;
Expand All @@ -39,6 +40,7 @@ class AudioTile extends StatefulWidget with WatchItStatefulWidgetMixin {

final bool isPlayerPlaying;
final void Function()? onTap;
final void Function()? onTitleTap;
final void Function(String text)? onSubTitleTap;
final void Function(Audio audio)? insertIntoQueue;
final bool showLeading;
Expand Down Expand Up @@ -78,6 +80,9 @@ class _AudioTileState extends State<AudioTile> {
),
};

const titleOverflow = TextOverflow.ellipsis;
const titleMaxLines = 1;

return MouseRegion(
key: ObjectKey(widget.audio),
onEnter: (e) {
Expand Down Expand Up @@ -111,11 +116,18 @@ class _AudioTileState extends State<AudioTile> {
},
title: Padding(
padding: const EdgeInsets.only(right: kYaruPagePadding),
child: Text(
widget.audio.title ?? l10n.unknown,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
child: widget.onTitleTap == null
? Text(
widget.audio.title ?? l10n.unknown,
overflow: titleOverflow,
maxLines: titleMaxLines,
)
: TapAbleText(
onTap: widget.onTitleTap,
text: widget.audio.title ?? l10n.unknown,
overflow: titleOverflow,
maxLines: titleMaxLines,
),
),
subtitle: TapAbleText(
text: subTitle,
Expand Down
37 changes: 7 additions & 30 deletions lib/library/library_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {

Future<bool> init() async {
await _service.init();

_propertiesChangedSub ??=
_service.propertiesChanged.listen((_) => notifyListeners());

notifyListeners();
return true;
}
Expand All @@ -41,21 +39,19 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
}
}

bool isPageInLibrary(String? pageId) => _service.isPageInLibrary(pageId);

//
// Liked Audios
//
List<Audio> get likedAudios => _service.likedAudios;

void addLikedAudio(Audio audio, [bool notify = true]) =>
_service.addLikedAudio(audio, notify);

void addLikedAudios(List<Audio> audios) => _service.addLikedAudios(audios);

void removeLikedAudios(List<Audio> audios) =>
_service.removeLikedAudios(audios);

bool liked(Audio? audio) => audio == null ? false : _service.liked(audio);

void removeLikedAudio(Audio audio, [bool notify = true]) =>
_service.removeLikedAudio(audio, notify);

Expand All @@ -67,7 +63,6 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
int get starredStationsLength => _service.starredStations.length;
void addStarredStation(String uuid, List<Audio> audios) =>
_service.addStarredStation(uuid, audios);

void unStarStation(String uuid) {
_service.unStarStation(uuid);
if (selectedPageId == uuid) {
Expand Down Expand Up @@ -108,34 +103,23 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
List<Audio> getPlaylistAt(int index) =>
playlists.entries.elementAt(index).value.toList();
List<Audio>? getPlaylistById(String id) => _service.playlists[id];

bool isPlaylistSaved(String? id) => _service.isPlaylistSaved(id);

Future<void> addPlaylist(String name, List<Audio> audios) async =>
_service.addPlaylist(name, audios);

Future<void> updatePlaylist(String id, List<Audio> audios) async =>
_service.updatePlaylist(id, audios);

void removePlaylist(String id) {
_service.removePlaylist(id);
pop();
}

void updatePlaylistName(String oldName, String newName) =>
_service.updatePlaylistName(oldName, newName);

void addAudioToPlaylist(String playlist, Audio audio) =>
_service.addAudioToPlaylist(playlist, audio);

void removeAudioFromPlaylist(String playlist, Audio audio) =>
_service.removeAudioFromPlaylist(playlist, audio);

void clearPlaylist(String id) => _service.clearPlaylist(id);

List<String> getPlaylistNames() =>
playlists.entries.map((e) => e.key).toList();

void moveAudioInPlaylist({
required int oldIndex,
required int newIndex,
Expand All @@ -147,37 +131,32 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
id: id,
);

//
// Podcasts
//

Map<String, List<Audio>> get podcasts => _service.podcasts;
int get podcastsLength => podcasts.length;
void addPodcast(String feedUrl, List<Audio> audios) =>
_service.addPodcast(feedUrl, audios);

void removePodcast(String feedUrl) {
_service.removePodcast(feedUrl);
pop();
}

bool isPodcastSubscribed(String? feedUrl) =>
feedUrl == null ? false : podcasts.containsKey(feedUrl);

bool podcastUpdateAvailable(String feedUrl) =>
_service.podcastUpdateAvailable(feedUrl);

int? get podcastUpdatesLength => _service.podcastUpdatesLength;

void removePodcastUpdate(String feedUrl) =>
_service.removePodcastUpdate(feedUrl);

int get downloadsLength => _service.downloads.length;

String? getDownload(String? url) =>
url == null ? null : _service.downloads[url];

bool feedHasDownload(String? feedUrl) =>
feedUrl == null ? false : _service.feedHasDownloads(feedUrl);

int get feedsWithDownloadsLength => _service.feedsWithDownloadsLength;

Future<void> reorderPodcast({
Expand All @@ -198,16 +177,16 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
List<Audio> getAlbumAt(int index) =>
pinnedAlbums.entries.elementAt(index).value.toList();
bool isPinnedAlbum(String name) => pinnedAlbums.containsKey(name);

void addPinnedAlbum(String name, List<Audio> audios) =>
_service.addPinnedAlbum(name, audios);

void removePinnedAlbum(String name) {
_service.removePinnedAlbum(name);
pop();
}

/// Navigation inside the Library
//
// Navigation inside the Library
//

String? get selectedPageId => _service.selectedPageId;
void _setSelectedPageId(String pageId) => _service.setSelectedPageId(pageId);
Expand Down Expand Up @@ -239,8 +218,6 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {

bool get canPop => _masterNavigatorKey.currentState?.canPop() == true;

bool isPageInLibrary(String? pageId) => _service.isPageInLibrary(pageId);

@override
void didPop(Route route, Route? previousRoute) {
final pageId = previousRoute?.settings.name;
Expand Down
3 changes: 0 additions & 3 deletions lib/player/player_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:safe_change_notifier/safe_change_notifier.dart';

Expand All @@ -24,7 +23,6 @@ class PlayerModel extends SafeChangeNotifier {
VideoController get controller => _playerService.controller;

StreamSubscription<bool>? _propertiesChangedSub;
StreamSubscription<List<ConnectivityResult>>? _connectivitySubscription;

Stream<String?> get onlineArtError => _onlineArtService.error;

Expand Down Expand Up @@ -154,7 +152,6 @@ class PlayerModel extends SafeChangeNotifier {
@override
Future<void> dispose() async {
await _propertiesChangedSub?.cancel();
await _connectivitySubscription?.cancel();
super.dispose();
}
}
2 changes: 1 addition & 1 deletion lib/player/view/player_title_and_artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class PlayerTitleAndArtist extends StatelessWidget with WatchItMixin {
TextStyle _fullHeightTitleTextStyle(ThemeData theme) {
return TextStyle(
fontWeight: largeTextWeight,
fontSize: 30,
fontSize: 26,
color: theme.colorScheme.onSurface,
);
}
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 @@ -259,7 +259,9 @@ class SearchModel extends SafeChangeNotifier {
SearchType.radioName => await radioNameSearch(_searchQuery)
.then(
(v) => setRadioSearchResult(
v?.map((e) => Audio.fromStation(e)).toList(),
_searchQuery == null || _searchQuery!.isEmpty
? null
: v?.map((e) => Audio.fromStation(e)).toList(),
),
)
.then((_) => _loading = false),
Expand Down
24 changes: 15 additions & 9 deletions lib/search/view/sliver_radio_search_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import '../../common/view/no_search_result_page.dart';
import '../../common/view/offline_page.dart';
import '../../common/view/snackbars.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../../player/player_model.dart';
import '../../radio/radio_model.dart';
import '../../radio/view/radio_connect_snackbar.dart';
import '../../radio/view/station_page.dart';
import '../search_model.dart';

class SliverRadioSearchResults extends StatefulWidget
Expand Down Expand Up @@ -69,7 +71,9 @@ class _SliverRadioSearchResultsState extends State<SliverRadioSearchResults> {
}

final radioSearchResult =
watchPropertyValue((SearchModel m) => m.radioSearchResult);
watchPropertyValue((SearchModel m) => m.radioSearchResult)
?.where((e) => e.uuid != null);

final searchQuery = watchPropertyValue((SearchModel m) => m.searchQuery);
final searchType = watchPropertyValue((SearchModel m) => m.searchType);
final loading = watchPropertyValue((SearchModel m) => m.loading);
Expand Down Expand Up @@ -103,14 +107,16 @@ class _SliverRadioSearchResultsState extends State<SliverRadioSearchResults> {
selected: currentAudio == station,
pageId: station.uuid!,
audio: station,
onTap: station.uuid == null
? null
: () {
di<PlayerModel>().startPlaylist(
audios: [station],
listName: station.uuid!,
).then((_) => di<RadioModel>().clickStation(station));
},
onTitleTap: () => di<LibraryModel>().push(
pageId: station.uuid!,
builder: (context) => StationPage(station: station),
),
onTap: () {
di<PlayerModel>().startPlaylist(
audios: [station],
listName: station.uuid!,
).then((_) => di<RadioModel>().clickStation(station));
},
);
},
);
Expand Down

0 comments on commit 27ab963

Please sign in to comment.