Skip to content

Commit

Permalink
Most browsing tasks work now. Initial migration code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Komodo5197 committed Dec 19, 2023
1 parent e5b0a68 commit 2444d93
Show file tree
Hide file tree
Showing 23 changed files with 1,187 additions and 725 deletions.
2 changes: 1 addition & 1 deletion lib/components/AlbumScreen/album_screen_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _AlbumScreenContentState extends State<AlbumScreenContent> {
// if not in playlist, try splitting up tracks by disc numbers
// if first track has a disc number, let's assume the rest has it too
if (widget.parent.type != "Playlist" &&
widget.children[0].parentIndexNumber != null) {
widget.children.isNotEmpty && widget.children[0].parentIndexNumber != null) {
int? lastDiscNumber;
for (var child in widget.children) {
if (child.parentIndexNumber != null &&
Expand Down
40 changes: 24 additions & 16 deletions lib/components/AlbumScreen/item_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,35 @@ class ItemInfo extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (item.type != "Playlist") _IconAndText(
iconData: Icons.person,
textSpan: TextSpan(
children: ArtistsTextSpans(
item,
null,
context,
false,
),
)
),
if (item.type != "Playlist")
_IconAndText(
iconData: Icons.person,
textSpan: TextSpan(
children: ArtistsTextSpans(
item,
null,
context,
false,
),
)),
_IconAndText(
iconData: Icons.music_note,
textSpan: TextSpan(text: AppLocalizations.of(context)!.songCount(itemSongs))),
textSpan: TextSpan(
text: (itemSongs == (item.childCount ?? itemSongs))
? AppLocalizations.of(context)!.songCount(itemSongs)
: AppLocalizations.of(context)!
.offlineSongCount(item.childCount!, itemSongs))),
_IconAndText(
iconData: Icons.timer,
textSpan: TextSpan(text: printDuration(Duration(
microseconds:
item.runTimeTicks == null ? 0 : item.runTimeTicks! ~/ 10)))),
textSpan: TextSpan(
text: printDuration(Duration(
microseconds: item.runTimeTicks == null
? 0
: item.runTimeTicks! ~/ 10)))),
if (item.type != "Playlist")
_IconAndText(iconData: Icons.event, textSpan: TextSpan(text: item.productionYearString))
_IconAndText(
iconData: Icons.event,
textSpan: TextSpan(text: item.productionYearString))
],
);
}
Expand Down
42 changes: 36 additions & 6 deletions lib/components/AlbumScreen/song_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '../favourite_button.dart';
import '../album_image.dart';
import '../print_duration.dart';
import '../error_snackbar.dart';
import 'download_dialog.dart';
import 'downloaded_indicator.dart';

enum SongListTileMenuItems {
Expand All @@ -29,6 +30,7 @@ enum SongListTileMenuItems {
goToAlbum,
addFavourite,
removeFavourite,
download,
}

class SongListTile extends StatefulWidget {
Expand Down Expand Up @@ -226,14 +228,9 @@ class _SongListTileState extends State<SongListTile> {
// its metadata. This function also checks if widget.item.parentId is
// null.
late final bool canGoToAlbum;
late final BaseItemDto? album;
// TODO clean this long-term album storage back out - does it cross async bound?
final isarDownloads = GetIt.instance<IsarDownloads>();
if (widget.item == null) {
canGoToAlbum=false;
} else if (FinampSettingsHelper.finampSettings.isOffline) {
final isarDownloads = GetIt.instance<IsarDownloads>();
album = isarDownloads.getAlbumDownloadFromSong(widget.item)?.baseItem;
canGoToAlbum = album != null && widget.item.albumId != widget.parentId;
} else {
canGoToAlbum=widget.item.albumId != widget.parentId;
}
Expand Down Expand Up @@ -338,6 +335,16 @@ class _SongListTileState extends State<SongListTile> {
title: Text(AppLocalizations.of(context)!.addFavourite),
),
),
// TODO add delete option
PopupMenuItem<SongListTileMenuItems>(
enabled: !isOffline,
value: SongListTileMenuItems.download,
child: ListTile(
leading: const Icon(Icons.file_download),
title: Text(AppLocalizations.of(context)!.downloadItem),
enabled: !isOffline,
),
),
],
);

Expand Down Expand Up @@ -420,7 +427,15 @@ class _SongListTileState extends State<SongListTile> {
break;
case SongListTileMenuItems.goToAlbum:

BaseItemDto? album;
if (! FinampSettingsHelper.finampSettings.isOffline) {
// The album should always be downloaded if the song is
album = isarDownloads.getAlbumDownloadFromSong(widget.item)?.baseItem;
if (album==null){
errorSnackbar("Could not locate downloaded album.", context);
break;
}
} else {
// If online, get the album's BaseItemDto from the server.
try {
album =
Expand All @@ -442,6 +457,21 @@ class _SongListTileState extends State<SongListTile> {
break;
case null:
break;
case SongListTileMenuItems.download:
var item = DownloadStub.fromItem(type: DownloadItemType.song, item: widget.item);
if (FinampSettingsHelper
.finampSettings.downloadLocationsMap.length ==
1) {
await isarDownloads.addDownload(stub: item, downloadLocation: FinampSettingsHelper
.finampSettings.downloadLocationsMap.values.first);
} else {
await showDialog(
context: context,
builder: (context) => DownloadDialog(
item: item,
),
);
}
}
},
child: widget.isSong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get_it/get_it.dart';

import '../../models/finamp_models.dart';
import '../../services/downloads_helper.dart';
import '../../services/isar_downloads.dart';
import '../../services/process_artist.dart';
import '../album_image.dart';

Expand Down
20 changes: 7 additions & 13 deletions lib/components/DownloadsScreen/album_file_size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:get_it/get_it.dart';

import '../../models/finamp_models.dart';
import '../../services/downloads_helper.dart';
import '../../services/isar_downloads.dart';

class AlbumFileSize extends StatelessWidget {
const AlbumFileSize({Key? key, required this.downloadedParent})
Expand All @@ -13,19 +14,12 @@ class AlbumFileSize extends StatelessWidget {

@override
Widget build(BuildContext context) {
DownloadsHelper downloadsHelper = GetIt.instance<DownloadsHelper>();
int totalSize = 0;

/*for (final item in downloadedParent.downloadedChildren.values) {
DownloadedSong? downloadedSong =
downloadsHelper.getDownloadedSong(item.id);
if (downloadedSong?.mediaSourceInfo.size != null) {
totalSize += downloadedSong!.mediaSourceInfo.size!;
final isarDownloader = GetIt.instance<IsarDownloads>();
return FutureBuilder(future: isarDownloader.getFileSize(downloadedParent), builder: (context, snapshot) {
if (snapshot.hasData){
return Text(FileSize.getSize(snapshot.data));
}
}*/
// TODO implement size retrieval - set recursion limit? How to get image sizes?

return Text(FileSize.getSize(totalSize));
return const Text("");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:get_it/get_it.dart';

import '../../services/downloads_helper.dart';
import '../../services/finamp_settings_helper.dart';
import '../../services/isar_downloads.dart';

class DownloadMissingImagesButton extends StatefulWidget {
const DownloadMissingImagesButton({Key? key}) : super(key: key);
Expand All @@ -30,25 +31,23 @@ class _DownloadMissingImagesButtonState
_enabled = false;
});

final downloadsHelper = GetIt.instance<DownloadsHelper>();

//final imagesDownloaded =
// await downloadsHelper.downloadMissingImages();
// TODO find something to do here
final isarDownloads = GetIt.instance<IsarDownloads>();
// TODO put in widget with updated name and text
await isarDownloads.repairAllDownloads();

if (!mounted) return;

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!
.downloadedMissingImages(0)),
.repairComplete),
));

setState(() {
_enabled = true;
});
}
: null,
icon: const Icon(Icons.image),
icon: const Icon(Icons.handyman),
tooltip: AppLocalizations.of(context)!.downloadMissingImages,
);
}
Expand Down
9 changes: 3 additions & 6 deletions lib/components/DownloadsScreen/downloaded_albums_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,15 @@ class _DownloadedSongsInAlbumListState
@override
Widget build(BuildContext context) {
final List<DownloadItem> children =
isarDownloads.getAllChildren(widget.parent);
// TODO figure out what to do here. Just filter for songs?
// Handle something like an individual song download?
// Just delete if you can't touch individual songs?
isarDownloads.getVisibleChildren(widget.parent);

return Column(children: [
//TODO use a list builder here
for (final song in children)
ListTile(
title: Text(song.baseItem?.name ?? "Unknown Name"),
leading: AlbumImage(item: song?.baseItem),
trailing: IconButton(
/*trailing: IconButton(
icon: const Icon(Icons.delete),
onPressed: () => showDialog(
context: context,
Expand All @@ -121,7 +118,7 @@ class _DownloadedSongsInAlbumListState
onAborted: () {},
),
),
),
),*/
subtitle: ItemMediaSourceInfo(
item: song,
),
Expand Down
Loading

0 comments on commit 2444d93

Please sign in to comment.