mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
feat: implemented hard deletion of downloaded files upon storage change or explicit user request
This commit is contained in:
parent
295795edc9
commit
87a3301912
3 changed files with 32 additions and 1 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ public class DownloaderManager {
|
|||
public void removeAll() {
|
||||
DownloadService.sendRemoveAllDownloads(context, DownloaderService.class, false);
|
||||
deleteAllDatabase();
|
||||
DownloadUtil.eraseDownloadFolder(context);
|
||||
}
|
||||
|
||||
private void loadDownloads() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.tempo.util;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.database.DatabaseProvider;
|
||||
import androidx.media3.database.StandaloneDatabaseProvider;
|
||||
|
|
@ -23,6 +24,8 @@ import java.io.File;
|
|||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookiePolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@UnstableApi
|
||||
|
|
@ -153,4 +156,32 @@ public final class DownloadUtil {
|
|||
.setCacheWriteDataSinkFactory(null)
|
||||
.setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
|
||||
}
|
||||
|
||||
public static synchronized void eraseDownloadFolder(Context context) {
|
||||
File directory = getDownloadDirectory(context);
|
||||
|
||||
ArrayList<File> files = listFiles(directory, new ArrayList<>());
|
||||
|
||||
for (File file : files) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized ArrayList<File> listFiles(File directory, ArrayList<File> files) {
|
||||
if (directory.isDirectory()) {
|
||||
File[] list = directory.listFiles();
|
||||
|
||||
if (list != null) {
|
||||
for (File file : list) {
|
||||
if (file.isFile() && file.getName().toLowerCase().endsWith(".exo")) {
|
||||
files.add(file);
|
||||
} else if (file.isDirectory()) {
|
||||
listFiles(file, files);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue