Skip to content

Commit

Permalink
fix: download not working other than jiosaavn
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 12, 2023
1 parent 3de153e commit 527ca25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
16 changes: 8 additions & 8 deletions lib/components/library/user_downloads/download_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class DownloadItem extends HookConsumerWidget {
final notifier = downloadManager.getStatusNotifier(track as SourcedTrack);

taskStatus.value = notifier?.value;
listener() {

void listener() {
taskStatus.value = notifier?.value;
}

downloadManager
.getStatusNotifier(track as SourcedTrack)
?.addListener(listener);
notifier?.addListener(listener);

return () {
downloadManager
.getStatusNotifier(track as SourcedTrack)
?.removeListener(listener);
notifier?.removeListener(listener);
};
}, [track]);

final isQueryingSourceInfo =
taskStatus.value == null || track is! SourcedTrack;

return ListTile(
leading: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
Expand All @@ -63,7 +63,7 @@ class DownloadItem extends HookConsumerWidget {
track.artists ?? <Artist>[],
mainAxisAlignment: WrapAlignment.start,
),
trailing: taskStatus.value == null || track is! SourcedTrack
trailing: isQueryingSourceInfo
? Text(
context.l10n.querying_info,
style: Theme.of(context).textTheme.labelMedium,
Expand Down
21 changes: 11 additions & 10 deletions lib/provider/download_manager_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class DownloadManagerProvider extends ChangeNotifier {
bool isActive(Track track) {
if ($backHistory.contains(track)) return true;

final SourcedTrack = mapToSourcedTrack(track);
final sourcedTrack = mapToSourcedTrack(track);

if (SourcedTrack == null) return false;
if (sourcedTrack == null) return false;

return dl
.getAllDownloads()
Expand All @@ -154,7 +154,7 @@ class DownloadManagerProvider extends ChangeNotifier {
download.status.value == DownloadStatus.queued,
)
.map((e) => e.request.url)
.contains(SourcedTrack.url);
.contains(sourcedTrack.getUrlOfCodec(downloadCodec));
}

/// For singular downloads
Expand All @@ -171,7 +171,8 @@ class DownloadManagerProvider extends ChangeNotifier {
}

if (track is SourcedTrack && track.codec == downloadCodec) {
final downloadTask = await dl.addDownload(track.url, savePath);
final downloadTask =
await dl.addDownload(track.getUrlOfCodec(downloadCodec), savePath);
if (downloadTask != null) {
$history.add(track);
}
Expand Down Expand Up @@ -219,24 +220,24 @@ class DownloadManagerProvider extends ChangeNotifier {
}

Future<void> removeFromQueue(SourcedTrack track) async {
await dl.removeDownload(track.url);
await dl.removeDownload(track.getUrlOfCodec(downloadCodec));
$history.remove(track);
}

Future<void> pause(SourcedTrack track) {
return dl.pauseDownload(track.url);
return dl.pauseDownload(track.getUrlOfCodec(downloadCodec));
}

Future<void> resume(SourcedTrack track) {
return dl.resumeDownload(track.url);
return dl.resumeDownload(track.getUrlOfCodec(downloadCodec));
}

Future<void> retry(SourcedTrack track) {
return addToQueue(track);
}

void cancel(SourcedTrack track) {
dl.cancelDownload(track.url);
dl.cancelDownload(track.getUrlOfCodec(downloadCodec));
}

void cancelAll() {
Expand All @@ -255,11 +256,11 @@ class DownloadManagerProvider extends ChangeNotifier {
}

ValueNotifier<DownloadStatus>? getStatusNotifier(SourcedTrack track) {
return dl.getDownload(track.url)?.status;
return dl.getDownload(track.getUrlOfCodec(downloadCodec))?.status;
}

ValueNotifier<double>? getProgressNotifier(SourcedTrack track) {
return dl.getDownload(track.url)?.progress;
return dl.getDownload(track.getUrlOfCodec(downloadCodec))?.progress;
}
}

Expand Down

0 comments on commit 527ca25

Please sign in to comment.