Removed unused download state listener

This commit is contained in:
CappielloAntonio 2022-01-03 15:12:49 +01:00
parent 72a471dd6d
commit d8350ed281
2 changed files with 2 additions and 53 deletions

View file

@ -32,36 +32,19 @@ public class DownloaderManager {
private static final String TAG = "DownloadTracker";
private final Context context;
private final CopyOnWriteArraySet<Listener> listeners;
private final HashMap<Uri, Download> downloads;
private final DownloadIndex downloadIndex;
public interface Listener {
void onDownloadsChanged();
}
@SuppressLint("UnsafeOptInUsageError")
public DownloaderManager(Context context, DownloadManager downloadManager) {
this.context = context.getApplicationContext();
listeners = new CopyOnWriteArraySet<>();
downloads = new HashMap<>();
downloadIndex = downloadManager.getDownloadIndex();
downloadManager.addListener(new DownloadManagerListener());
loadDownloads();
}
@SuppressLint("UnsafeOptInUsageError")
public void addListener(Listener listener) {
checkNotNull(listener);
listeners.add(listener);
}
public void removeListener(Listener listener) {
listeners.remove(listener);
}
@SuppressLint("UnsafeOptInUsageError")
private DownloadRequest buildDownloadRequest(MediaItem mediaItem) {
return DownloadHelper.forMediaItem(context, mediaItem).getDownloadRequest(Util.getUtf8Bytes(checkNotNull(mediaItem.mediaId)));
@ -126,24 +109,6 @@ public class DownloaderManager {
}
}
private class DownloadManagerListener implements DownloadManager.Listener {
@Override
public void onDownloadChanged(DownloadManager downloadManager, Download download, @Nullable Exception finalException) {
downloads.put(download.request.uri, download);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
}
}
@Override
public void onDownloadRemoved(DownloadManager downloadManager, Download download) {
downloads.remove(download.request.uri);
for (Listener listener : listeners) {
listener.onDownloadsChanged();
}
}
}
private static DownloadRepository getDownloadRepository() {
return new DownloadRepository(App.getInstance());
}