Skip to content

Commit

Permalink
chore: better constant refactoring (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Jan 25, 2025
1 parent 6469fc8 commit af765fa
Show file tree
Hide file tree
Showing 51 changed files with 505 additions and 414 deletions.
5 changes: 3 additions & 2 deletions lib/app/view/master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../app_config.dart';
import '../../common/page_ids.dart';
import '../../common/view/back_gesture.dart';
import '../../common/view/global_keys.dart';
import '../../common/view/header_bar.dart';
Expand Down Expand Up @@ -64,7 +65,7 @@ class MasterDetailPage extends StatelessWidget with WatchItMixin {
if (context.showMasterPanel) const VerticalDivider(),
Expanded(
child: Navigator(
initialRoute: libraryModel.selectedPageId ?? kSearchPageId,
initialRoute: libraryModel.selectedPageId ?? PageIDs.searchPage,
onDidRemovePage: (page) {},
key: libraryModel.masterNavigatorKey,
observers: [libraryModel],
Expand Down Expand Up @@ -122,7 +123,7 @@ class MasterPanel extends StatelessWidget {
return MasterTile(
key: ValueKey(item.pageId),
onTap: () {
if (item.pageId == kNewPlaylistPageId) {
if (item.pageId == PageIDs.newPlaylist) {
showDialog(
context: context,
builder: (context) {
Expand Down
18 changes: 9 additions & 9 deletions lib/app/view/master_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:flutter/material.dart';

import '../../app_config.dart';
import '../../common/data/audio_type.dart';
import '../../common/page_ids.dart';
import '../../common/view/icons.dart';
import '../../common/view/side_bar_fall_back_image.dart';
import '../../common/view/theme.dart';
import '../../constants.dart';
import '../../home/home_page.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
Expand Down Expand Up @@ -47,7 +47,7 @@ List<MasterItem> createMasterItems({required LibraryModel libraryModel}) {
titleBuilder: (context) => Text(context.l10n.search),
pageBuilder: (_) => const SearchPage(),
iconBuilder: (_) => Icon(Iconz.search),
pageId: kSearchPageId,
pageId: PageIDs.searchPage,
),
MasterItem(
titleBuilder: (context) => Text(context.l10n.local),
Expand All @@ -56,7 +56,7 @@ List<MasterItem> createMasterItems({required LibraryModel libraryModel}) {
audioType: AudioType.local,
selected: selected,
),
pageId: kLocalAudioPageId,
pageId: PageIDs.localAudio,
),
MasterItem(
titleBuilder: (context) => Text(context.l10n.radio),
Expand All @@ -65,7 +65,7 @@ List<MasterItem> createMasterItems({required LibraryModel libraryModel}) {
audioType: AudioType.radio,
selected: selected,
),
pageId: kRadioPageId,
pageId: PageIDs.radio,
),
MasterItem(
titleBuilder: (context) => Text(context.l10n.podcasts),
Expand All @@ -74,33 +74,33 @@ List<MasterItem> createMasterItems({required LibraryModel libraryModel}) {
audioType: AudioType.podcast,
selected: selected,
),
pageId: kPodcastsPageId,
pageId: PageIDs.podcasts,
),
if (isMobilePlatform)
MasterItem(
titleBuilder: (context) => Text(context.l10n.settings),
iconBuilder: (selected) =>
Icon(selected ? Iconz.settingsFilled : Iconz.settings),
pageBuilder: (context) => const SettingsPage(),
pageId: kSettingsPageId,
pageId: PageIDs.settings,
),
if (isMobilePlatform)
MasterItem(
titleBuilder: (context) => Text(context.l10n.home),
iconBuilder: (selected) =>
Icon(selected ? Iconz.homeFilled : Iconz.home),
pageBuilder: (context) => const HomePage(),
pageId: kHomePageId,
pageId: PageIDs.homePage,
),
MasterItem(
iconBuilder: (selected) => Icon(Iconz.plus),
titleBuilder: (context) => Text(context.l10n.add),
pageBuilder: (_) => const SizedBox.shrink(),
pageId: kNewPlaylistPageId,
pageId: PageIDs.newPlaylist,
),
MasterItem(
titleBuilder: (context) => Text(context.l10n.likedSongs),
pageId: kLikedAudiosPageId,
pageId: PageIDs.likedAudios,
pageBuilder: (_) => const LikedAudioPage(),
subtitleBuilder: (context) => Text(context.l10n.playlist),
iconBuilder: (selected) => LikedAudioPageIcon(selected: selected),
Expand Down
8 changes: 4 additions & 4 deletions lib/app/view/master_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../common/data/audio_type.dart';
import '../../common/page_ids.dart';
import '../../common/view/icons.dart';
import '../../common/view/spaced_divider.dart';
import '../../common/view/ui_constants.dart';
import '../../constants.dart';
import '../../extensions/build_context_x.dart';
import '../../library/library_model.dart';
import '../../player/player_model.dart';
import '../../common/view/icons.dart';
import '../../common/view/spaced_divider.dart';
import '../../radio/radio_model.dart';

class MasterTile extends StatelessWidget {
Expand Down Expand Up @@ -46,7 +46,7 @@ class MasterTile extends StatelessWidget {
);

final Widget tile;
if (pageId == kNewPlaylistPageId) {
if (pageId == PageIDs.newPlaylist) {
tile = _FramedMasterTile(tile: yaruMasterTile);
} else {
tile = yaruMasterTile;
Expand Down
3 changes: 2 additions & 1 deletion lib/app/view/mobile_musicpod_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:phoenix_theme/phoenix_theme.dart';
import 'package:watch_it/watch_it.dart';

import '../../app_config.dart';
import '../../common/page_ids.dart';
import '../../common/view/theme.dart';
import '../../constants.dart';
import '../../external_path/external_path_service.dart';
Expand Down Expand Up @@ -57,7 +58,7 @@ class _MobileMusicPodAppState extends State<MobileMusicPodApp> {
navigatorKey: libraryModel.masterNavigatorKey,
navigatorObservers: [libraryModel],
initialRoute: isMobilePlatform
? (libraryModel.selectedPageId ?? kHomePageId)
? (libraryModel.selectedPageId ?? PageIDs.homePage)
: null,
onGenerateRoute: (settings) {
final page = (masterItems.firstWhereOrNull(
Expand Down
24 changes: 13 additions & 11 deletions lib/app/view/mobile_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';

import '../../common/page_ids.dart';
import '../../common/view/icons.dart';
import '../../common/view/theme.dart';
import '../../common/view/ui_constants.dart';
import '../../constants.dart';
import '../../extensions/build_context_x.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';

class MobileNavigationBar extends StatelessWidget with WatchItMixin {
const MobileNavigationBar({super.key});
Expand All @@ -31,34 +32,35 @@ class MobileNavigationBar extends StatelessWidget with WatchItMixin {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
isSelected: selectedPageId == kHomePageId,
isSelected: selectedPageId == PageIDs.homePage,
selectedIcon: Icon(Iconz.homeFilled),
icon: Icon(Iconz.home),
tooltip: l10n.home,
onPressed: () => di<LibraryModel>().push(pageId: kHomePageId),
onPressed: () =>
di<LibraryModel>().push(pageId: PageIDs.homePage),
),
IconButton(
isSelected: selectedPageId == kLocalAudioPageId,
isSelected: selectedPageId == PageIDs.localAudio,
selectedIcon: Icon(Iconz.localAudioFilled),
icon: Icon(Iconz.localAudio),
tooltip: l10n.local,
onPressed: () =>
di<LibraryModel>().push(pageId: kLocalAudioPageId),
di<LibraryModel>().push(pageId: PageIDs.localAudio),
),
IconButton(
isSelected: selectedPageId == kRadioPageId,
isSelected: selectedPageId == PageIDs.radio,
selectedIcon: Icon(Iconz.radioFilled),
icon: Icon(Iconz.radio),
tooltip: l10n.radio,
onPressed: () => di<LibraryModel>().push(pageId: kRadioPageId),
onPressed: () => di<LibraryModel>().push(pageId: PageIDs.radio),
),
IconButton(
isSelected: selectedPageId == kPodcastsPageId,
isSelected: selectedPageId == PageIDs.podcasts,
selectedIcon: Icon(Iconz.podcastFilled),
icon: Icon(Iconz.podcast),
tooltip: l10n.podcasts,
onPressed: () =>
di<LibraryModel>().push(pageId: kPodcastsPageId),
di<LibraryModel>().push(pageId: PageIDs.podcasts),
),
],
),
Expand Down
29 changes: 29 additions & 0 deletions lib/common/file_names.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class FileNames {
static const likedAudios = 'likedAudios.json';
static const playlists = 'playlists.json';
static const pinnedAlbums = 'finallyFixedPinnedAlbums.json';
static const podcasts = 'podcasts.json';
static const podcastUpdates = 'podcastsupdates.json';
static const starredStations = 'uuidStarredStations.json';
static const lastPositions = 'lastPositions.json';
static const playerState = 'playerstate.json';
static const appState = 'appstate.json';
static const downloads = 'downloads.json';
static const feedsWithDownloads = 'feedswithdownloads.json';
static const coverStore = 'coverStore.json';

static const all = {
likedAudios,
playlists,
pinnedAlbums,
podcasts,
podcastUpdates,
starredStations,
lastPositions,
playerState,
appState,
downloads,
feedsWithDownloads,
coverStore,
};
}
21 changes: 21 additions & 0 deletions lib/common/page_ids.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class PageIDs {
static const settings = 'settings';
static const homePage = 'homePage';
static const selectedPage = 'selectedPageId';
static const localAudio = 'localAudio';
static const podcasts = 'podcasts';
static const radio = 'radio';
static const newPlaylist = 'newPlaylist';
static const likedAudios = 'likedAudios';
static const searchPage = 'searchPageId';

static const permanent = {
homePage,
searchPage,
likedAudios,
localAudio,
podcasts,
radio,
settings,
};
}
6 changes: 3 additions & 3 deletions lib/common/view/audio_tile_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';

import '../../constants.dart';
import '../../extensions/build_context_x.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
Expand All @@ -13,6 +12,7 @@ import '../../player/player_model.dart';
import '../../playlists/view/add_to_playlist_dialog.dart';
import '../data/audio.dart';
import '../data/audio_type.dart';
import '../page_ids.dart';
import 'audio_tile_image.dart';
import 'icons.dart';
import 'like_all_icon.dart';
Expand Down Expand Up @@ -135,7 +135,7 @@ class AudioTileBottomSheet extends StatelessWidget {
children: [
_Button(
onPressed: () {
playlistId == kLikedAudiosPageId
playlistId == PageIDs.likedAudios
? libraryModel.removeLikedAudios(audios)
: libraryModel.removeAudiosFromPlaylist(
id: playlistId,
Expand All @@ -147,7 +147,7 @@ class AudioTileBottomSheet extends StatelessWidget {
),
_ButtonLabel(
label:
'${l10n.removeFrom} ${playlistId == kLikedAudiosPageId ? l10n.likedSongs : playlistId}',
'${l10n.removeFrom} ${playlistId == PageIDs.likedAudios ? l10n.likedSongs : playlistId}',
),
],
),
Expand Down
57 changes: 36 additions & 21 deletions lib/common/view/audio_tile_option_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../app_config.dart';
import '../../constants.dart';
import '../../extensions/build_context_x.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../../player/player_model.dart';
import '../../playlists/view/add_to_playlist_dialog.dart';
import '../data/audio.dart';
import '../data/audio_type.dart';
import '../page_ids.dart';
import 'audio_tile_bottom_sheet.dart';
import 'icons.dart';
import 'meta_data_dialog.dart';
Expand Down Expand Up @@ -63,26 +63,36 @@ class AudioTileOptionButton extends StatelessWidget {
tooltip: l10n.moreOptions,
padding: EdgeInsets.zero,
itemBuilder: (context) {
final currentAudioType = di<PlayerModel>().audio?.audioType;
return [
if (audios.none((e) => e.audioType == AudioType.radio))
PopupMenuItem(
onTap: () {
di<PlayerModel>().insertIntoQueue(audios);
showSnackBar(
context: context,
content: Text(
'${l10n.addedTo} ${l10n.queue}: $searchTerm',
),
);
if (di<PlayerModel>().audio?.audioType == AudioType.radio) {
di<PlayerModel>()
.startPlaylist(audios: audios, listName: playlistId);
} else {
di<PlayerModel>().insertIntoQueue(audios);
showSnackBar(
context: context,
content: Text(
'${l10n.addedTo} ${l10n.queue}: $searchTerm',
),
);
}
},
child: YaruTile(
leading: Icon(Iconz.insertIntoQueue),
title: Text(l10n.playNext),
title: Text(
currentAudioType == AudioType.radio
? l10n.playAll
: l10n.playNext,
),
),
),
if (allowRemove)
PopupMenuItem(
onTap: () => playlistId == kLikedAudiosPageId
onTap: () => playlistId == PageIDs.likedAudios
? libraryModel.removeLikedAudios(audios)
: libraryModel.removeAudiosFromPlaylist(
id: playlistId,
Expand All @@ -91,7 +101,7 @@ class AudioTileOptionButton extends StatelessWidget {
child: YaruTile(
leading: Icon(Iconz.remove),
title: Text(
'${l10n.removeFrom} ${playlistId == kLikedAudiosPageId ? l10n.likedSongs : playlistId}',
'${l10n.removeFrom} ${playlistId == PageIDs.likedAudios ? l10n.likedSongs : playlistId}',
),
),
),
Expand All @@ -109,18 +119,23 @@ class AudioTileOptionButton extends StatelessWidget {
),
),
),
PopupMenuItem(
onTap: () => showDialog(
context: context,
builder: (context) => MetaDataContent.dialog(audio: audios.first),
),
child: YaruTile(
leading: Icon(Iconz.info),
title: Text(
'${l10n.showMetaData} ...',
if (audios.none(
(e) => e.audioType == AudioType.podcast,
) &&
audios.length == 1)
PopupMenuItem(
onTap: () => showDialog(
context: context,
builder: (context) =>
MetaDataContent.dialog(audio: audios.first),
),
child: YaruTile(
leading: Icon(Iconz.info),
title: Text(
'${l10n.showMetaData} ...',
),
),
),
),
if (audios.none((e) => e.audioType == AudioType.radio))
PopupMenuItem(
enabled: false,
Expand Down
Loading

0 comments on commit af765fa

Please sign in to comment.