Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unnecessary popping of pages + minor refactoring #1067

Merged
merged 1 commit into from
Nov 28, 2024
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
41 changes: 19 additions & 22 deletions lib/library/library_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ 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) {
pop();
}
}
void unStarStation(String uuid) => _service.unStarStation(uuid);

bool isStarredStation(String? uuid) =>
uuid?.isNotEmpty == false ? false : _service.isStarredStation(uuid);
Expand Down Expand Up @@ -110,10 +105,7 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
_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 removePlaylist(String id) => _service.removePlaylist(id);

void updatePlaylistName(String oldName, String newName) =>
_service.updatePlaylistName(oldName, newName);
Expand Down Expand Up @@ -147,10 +139,7 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
int get podcastsLength => podcasts.length;
void addPodcast(String feedUrl, List<Audio> audios) =>
_service.addPodcast(feedUrl, audios);
void removePodcast(String feedUrl) {
_service.removePodcast(feedUrl);
pop();
}
void removePodcast(String feedUrl) => _service.removePodcast(feedUrl);

bool isPodcastSubscribed(String? feedUrl) =>
feedUrl == null ? false : podcasts.containsKey(feedUrl);
Expand Down Expand Up @@ -187,10 +176,7 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
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();
}
void removePinnedAlbum(String name) => _service.removePinnedAlbum(name);

//
// Navigation inside the Library
Expand All @@ -203,11 +189,16 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
required String pageId,
Widget Function(BuildContext)? builder,
bool maintainState = false,
bool replace = false,
}) async {
final inLibrary = isPageInLibrary(pageId);
assert(inLibrary || builder != null);
if (inLibrary) {
await _masterNavigatorKey.currentState?.pushNamed(pageId);
if (replace) {
await _masterNavigatorKey.currentState?.pushReplacementNamed(pageId);
} else {
await _masterNavigatorKey.currentState?.pushNamed(pageId);
}
} else if (builder != null) {
final materialPageRoute = MaterialPageRoute(
builder: (context) => useSystemBackGestures
Expand All @@ -218,9 +209,15 @@ class LibraryModel extends SafeChangeNotifier implements NavigatorObserver {
name: pageId,
),
);
await _masterNavigatorKey.currentState?.push(
materialPageRoute,
);
if (replace) {
await _masterNavigatorKey.currentState?.pushReplacement(
materialPageRoute,
);
} else {
await _masterNavigatorKey.currentState?.push(
materialPageRoute,
);
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions lib/library/library_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ class LibraryService {

void removePlaylist(String id) {
if (_playlists.containsKey(id)) {
_playlists.remove(id);
writeAudioMap(_playlists, kPlaylistsFileName)
.then((_) => _propertiesChangedController.add(true));
writeAudioMap(_playlists, kPlaylistsFileName).then(
(_) {
_playlists.remove(id);
_propertiesChangedController.add(true);
},
);
}
}

Expand Down
35 changes: 19 additions & 16 deletions lib/playlists/view/manual_add_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class ManualAddDialog extends StatelessWidget {
child: onlyPlaylists
? Padding(
padding: const EdgeInsets.only(top: kLargestSpace),
child: PlaylistContent(
child: PlaylistEditDialogContent(
playlistName: context.l10n.createNewPlaylist,
libraryModel: di<LibraryModel>(),
allowCreate: true,
),
)
Expand All @@ -59,9 +58,8 @@ class ManualAddDialog extends StatelessWidget {
initialRoute: '/chose',
onGenerateRoute: (settings) {
Widget page = switch (settings.name) {
'/addPlaylist' => PlaylistContent(
'/addPlaylist' => PlaylistEditDialogContent(
playlistName: context.l10n.createNewPlaylist,
libraryModel: di<LibraryModel>(),
allowCreate: true,
),
'/addPodcast' => const AddPodcastContent(),
Expand Down Expand Up @@ -126,29 +124,28 @@ class SelectAddContent extends StatelessWidget {
}
}

class PlaylistContent extends StatefulWidget {
const PlaylistContent({
class PlaylistEditDialogContent extends StatefulWidget {
const PlaylistEditDialogContent({
super.key,
this.playlistName,
this.initialValue,
this.audios,
this.allowDelete = false,
this.allowRename = false,
this.allowCreate = false,
required this.libraryModel,
});

final LibraryModel libraryModel;
final List<Audio>? audios;
final String? playlistName;
final String? initialValue;
final bool allowRename, allowDelete, allowCreate;

@override
State<PlaylistContent> createState() => _PlaylistContentState();
State<PlaylistEditDialogContent> createState() =>
_PlaylistEditDialogContentState();
}

class _PlaylistContentState extends State<PlaylistContent> {
class _PlaylistEditDialogContentState extends State<PlaylistEditDialogContent> {
late TextEditingController _controller;
late TextEditingController _fileController;

Expand All @@ -171,6 +168,7 @@ class _PlaylistContentState extends State<PlaylistContent> {

@override
Widget build(BuildContext context) {
final libraryModel = di<LibraryModel>();
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand Down Expand Up @@ -215,9 +213,15 @@ class _PlaylistContentState extends State<PlaylistContent> {
),
if (widget.allowDelete && widget.playlistName != null)
OutlinedButton(
onPressed: () {
widget.libraryModel.removePlaylist(widget.playlistName!);
onPressed: () async {
Navigator.of(context).pop();
libraryModel.removePlaylist(widget.playlistName!);
di<LocalAudioModel>().localAudioindex =
LocalAudioView.playlists.index;
await libraryModel.push(
pageId: kLocalAudioPageId,
replace: true,
);
},
child: Text(
context.l10n.deletePlaylist,
Expand All @@ -228,7 +232,7 @@ class _PlaylistContentState extends State<PlaylistContent> {
onPressed: () {
di<LocalAudioModel>().localAudioindex =
LocalAudioView.playlists.index;
widget.libraryModel
libraryModel
..push(pageId: kLocalAudioPageId)
..updatePlaylistName(
widget.playlistName!,
Expand All @@ -245,7 +249,7 @@ class _PlaylistContentState extends State<PlaylistContent> {
onPressed: _controller.text.isEmpty
? null
: () async {
await widget.libraryModel
await libraryModel
.addPlaylist(
_controller.text,
_audios ?? widget.audios ?? [],
Expand All @@ -257,8 +261,7 @@ class _PlaylistContentState extends State<PlaylistContent> {
await Future.delayed(
const Duration(milliseconds: 300),
);
await widget.libraryModel
.push(pageId: _controller.text);
await libraryModel.push(pageId: _controller.text);
});
},
child: Text(
Expand Down
3 changes: 1 addition & 2 deletions lib/playlists/view/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,11 @@ class _PlaylistControlPanel extends StatelessWidget with WatchItMixin {
content: SizedBox(
height: 200,
width: 500,
child: PlaylistContent(
child: PlaylistEditDialogContent(
playlistName: pageId,
initialValue: pageId,
allowDelete: true,
allowRename: true,
libraryModel: libraryModel,
),
),
),
Expand Down
9 changes: 7 additions & 2 deletions lib/podcasts/view/podcast_reorder_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ class PodcastReorderButton extends StatelessWidget with WatchItMixin {
final ascending =
watchPropertyValue((LibraryModel m) => m.showPodcastAscending(feedUrl));

final podcastSubscribed =
watchPropertyValue((LibraryModel m) => m.isPodcastSubscribed(feedUrl));

return IconButton(
tooltip: context.l10n.reorder,
onPressed: () => di<LibraryModel>()
.reorderPodcast(feedUrl: feedUrl, ascending: !ascending),
onPressed: podcastSubscribed
? () => di<LibraryModel>()
.reorderPodcast(feedUrl: feedUrl, ascending: !ascending)
: null,
icon: Iconz.ascending == Iconz.materialAscending && ascending
? Transform.flip(
flipX: true,
Expand Down
94 changes: 0 additions & 94 deletions needs_translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,24 +611,7 @@
"listenBrainzApiKeyEmpty"
],

"es": [
"exposeToListenBrainzTitle",
"exposeToListenBrainzSubTitle",
"listenBrainzApiKey",
"listenBrainzApiKeyEmpty"
],

"eu": [
"play",
"pause",
"stop",
"shuffle",
"repeat",
"repeatAll",
"next",
"back",
"fastForward30",
"rewind10",
"fullWindow",
"leaveFullWindow",
"fullScreen",
Expand Down Expand Up @@ -1228,19 +1211,6 @@
"regionNone"
],

"it": [
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
"lastfmSecret",
"lastfmApiKeyEmpty",
"lastfmSecretEmpty",
"exposeToListenBrainzTitle",
"exposeToListenBrainzSubTitle",
"listenBrainzApiKey",
"listenBrainzApiKeyEmpty"
],

"nl": [
"noStationFound",
"nothingFound",
Expand Down Expand Up @@ -3014,71 +2984,7 @@
],

"ru": [
"fullScreen",
"leaveFullScreen",
"local",
"saveAndAuthorize",
"copyToClipBoard",
"insertedIntoQueue",
"downloadsDirectory",
"downloadsDirectoryDescription",
"downloadsChangeWarning",
"disconnectedFrom",
"useMoreAnimationsTitle",
"useMoreAnimationsDescription",
"showPositionDurationTitle",
"showPositionDurationDescription",
"unPinAlbum",
"language",
"duration",
"radioTagDisclaimerTitle",
"radioTagDisclaimerSubTitle",
"podcastFeedLoadingTimeout",
"gitHubClientConnectError",
"replayEpisode",
"replayAllEpisodes",
"checkForUpdates",
"playbackWillStopIn",
"schedulePlaybackStopTimer",
"alwaysAsk",
"hideToTray",
"closeBtnAction",
"whenCloseBtnClicked",
"closeApp",
"closeMusicPod",
"confirmCloseOrHideTip",
"doNotAskAgain",
"skipToLivStream",
"searchSimilarStation",
"onlineArtError",
"clicks",
"exposeOnlineHeadline",
"exposeToDiscordTitle",
"exposeToDiscordSubTitle",
"exposeToLastfmTitle",
"exposeToLastfmSubTitle",
"lastfmApiKey",
"lastfmSecret",
"lastfmApiKeyEmpty",
"lastfmSecretEmpty",
"exposeToListenBrainzTitle",
"exposeToListenBrainzSubTitle",
"listenBrainzApiKey",
"listenBrainzApiKeyEmpty",
"featureDisabledOnPlatform",
"regionNone",
"regionAfghanistan",
"regionAlandislands",
"regionAlbania",
"regionAlgeria",
"regionAmericansamoa",
"regionAndorra",
"regionAngolia",
"regionAnguilla",
"regionAntarctica",
"regionAntiguaandbarbuda",
"regionArgentina",
"regionArmenia",
"regionAruba",
"regionAustralia",
"regionAustria",
Expand Down