mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Removed unused download state listener
This commit is contained in:
parent
72a471dd6d
commit
d8350ed281
2 changed files with 2 additions and 53 deletions
|
|
@ -32,36 +32,19 @@ public class DownloaderManager {
|
||||||
private static final String TAG = "DownloadTracker";
|
private static final String TAG = "DownloadTracker";
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final CopyOnWriteArraySet<Listener> listeners;
|
|
||||||
private final HashMap<Uri, Download> downloads;
|
private final HashMap<Uri, Download> downloads;
|
||||||
private final DownloadIndex downloadIndex;
|
private final DownloadIndex downloadIndex;
|
||||||
|
|
||||||
public interface Listener {
|
|
||||||
void onDownloadsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("UnsafeOptInUsageError")
|
@SuppressLint("UnsafeOptInUsageError")
|
||||||
public DownloaderManager(Context context, DownloadManager downloadManager) {
|
public DownloaderManager(Context context, DownloadManager downloadManager) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
|
|
||||||
listeners = new CopyOnWriteArraySet<>();
|
|
||||||
downloads = new HashMap<>();
|
downloads = new HashMap<>();
|
||||||
downloadIndex = downloadManager.getDownloadIndex();
|
downloadIndex = downloadManager.getDownloadIndex();
|
||||||
|
|
||||||
downloadManager.addListener(new DownloadManagerListener());
|
|
||||||
loadDownloads();
|
loadDownloads();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("UnsafeOptInUsageError")
|
|
||||||
public void addListener(Listener listener) {
|
|
||||||
checkNotNull(listener);
|
|
||||||
listeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeListener(Listener listener) {
|
|
||||||
listeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("UnsafeOptInUsageError")
|
@SuppressLint("UnsafeOptInUsageError")
|
||||||
private DownloadRequest buildDownloadRequest(MediaItem mediaItem) {
|
private DownloadRequest buildDownloadRequest(MediaItem mediaItem) {
|
||||||
return DownloadHelper.forMediaItem(context, mediaItem).getDownloadRequest(Util.getUtf8Bytes(checkNotNull(mediaItem.mediaId)));
|
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() {
|
private static DownloadRepository getDownloadRepository() {
|
||||||
return new DownloadRepository(App.getInstance());
|
return new DownloadRepository(App.getInstance());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ import androidx.media3.session.MediaBrowser;
|
||||||
import androidx.media3.session.SessionToken;
|
import androidx.media3.session.SessionToken;
|
||||||
|
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.service.DownloaderService;
|
|
||||||
import com.cappielloantonio.play.service.DownloaderManager;
|
import com.cappielloantonio.play.service.DownloaderManager;
|
||||||
|
import com.cappielloantonio.play.service.DownloaderService;
|
||||||
import com.cappielloantonio.play.service.MediaService;
|
import com.cappielloantonio.play.service.MediaService;
|
||||||
import com.cappielloantonio.play.util.DownloadUtil;
|
import com.cappielloantonio.play.util.DownloadUtil;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
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 static final String TAG = "BaseActivity";
|
||||||
|
|
||||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||||
|
|
@ -37,7 +37,6 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
initializeBrowser();
|
initializeBrowser();
|
||||||
addDownloadListener();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -49,16 +48,9 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
releaseBrowser();
|
releaseBrowser();
|
||||||
removeDownloadListener();
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDownloadsChanged() {
|
|
||||||
// TODO Notificare all'item scaricato che lo stato di download è cambiato
|
|
||||||
// sampleAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkBatteryOptimization() {
|
private void checkBatteryOptimization() {
|
||||||
if (detectBatteryOptimization()) {
|
if (detectBatteryOptimization()) {
|
||||||
showBatteryOptimizationDialog();
|
showBatteryOptimizationDialog();
|
||||||
|
|
@ -110,12 +102,4 @@ public class BaseActivity extends AppCompatActivity implements DownloaderManager
|
||||||
DownloadService.startForeground(this, DownloaderService.class);
|
DownloadService.startForeground(this, DownloaderService.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDownloadListener() {
|
|
||||||
downloaderManager.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeDownloadListener() {
|
|
||||||
downloaderManager.removeListener(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue