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());
}

View file

@ -15,13 +15,13 @@ import androidx.media3.session.MediaBrowser;
import androidx.media3.session.SessionToken;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.service.DownloaderService;
import com.cappielloantonio.play.service.DownloaderManager;
import com.cappielloantonio.play.service.DownloaderService;
import com.cappielloantonio.play.service.MediaService;
import com.cappielloantonio.play.util.DownloadUtil;
import com.google.common.util.concurrent.ListenableFuture;
public class BaseActivity extends AppCompatActivity implements DownloaderManager.Listener {
public class BaseActivity extends AppCompatActivity {
private static final String TAG = "BaseActivity";
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
@ -37,7 +37,6 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
protected void onStart() {
super.onStart();
initializeBrowser();
addDownloadListener();
}
@Override
@ -49,16 +48,9 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
@Override
protected void onStop() {
releaseBrowser();
removeDownloadListener();
super.onStop();
}
@Override
public void onDownloadsChanged() {
// TODO Notificare all'item scaricato che lo stato di download è cambiato
// sampleAdapter.notifyDataSetChanged();
}
private void checkBatteryOptimization() {
if (detectBatteryOptimization()) {
showBatteryOptimizationDialog();
@ -110,12 +102,4 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
DownloadService.startForeground(this, DownloaderService.class);
}
}
private void addDownloadListener() {
downloaderManager.addListener(this);
}
private void removeDownloadListener() {
downloaderManager.removeListener(this);
}
}