fix: smol fixes

This commit is contained in:
rebelonion 2024-05-23 12:48:34 -05:00
parent 773b7f5dd0
commit 3d187a01ec
8 changed files with 67 additions and 19 deletions

View file

@ -347,7 +347,7 @@ class DownloadCompat {
}
@Deprecated("external storage is deprecated, use SAF instead")
fun removeDownloadCompat(context: Context, downloadedType: DownloadedType) {
fun removeDownloadCompat(context: Context, downloadedType: DownloadedType, toast: Boolean) {
val directory = if (downloadedType.type == MediaType.MANGA) {
File(
context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
@ -368,10 +368,13 @@ class DownloadCompat {
// Check if the directory exists and delete it recursively
if (directory.exists()) {
val deleted = directory.deleteRecursively()
if (deleted) {
Toast.makeText(context, "Successfully deleted", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, "Failed to delete directory", Toast.LENGTH_SHORT).show()
if (toast) {
if (deleted) {
Toast.makeText(context, "Successfully deleted", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(context, "Failed to delete directory", Toast.LENGTH_SHORT)
.show()
}
}
}
}

View file

@ -60,7 +60,7 @@ class DownloadsManager(private val context: Context) {
toast: Boolean = true,
onFinished: () -> Unit
) {
removeDownloadCompat(context, downloadedType)
removeDownloadCompat(context, downloadedType, toast)
downloadsList.remove(downloadedType)
CoroutineScope(Dispatchers.IO).launch {
removeDirectory(downloadedType, toast)

View file

@ -225,14 +225,16 @@ class AnimeDownloaderService : Service() {
task.episode
) ?: throw Exception("Failed to create output directory")
outputDir.findFile("${task.getTaskName().findValidName()}.mkv")?.delete()
val extension = ffExtension!!.getFileExtension()
outputDir.findFile("${task.getTaskName().findValidName()}.${extension.first}")?.delete()
val outputFile =
outputDir.createFile("video/x-matroska", "${task.getTaskName()}.mkv")
outputDir.createFile(extension.second, "${task.getTaskName()}.${extension.first}")
?: throw Exception("Failed to create output file")
var percent = 0
var totalLength = 0.0
val path = ffExtension!!.setDownloadPath(
val path = ffExtension.setDownloadPath(
this@AnimeDownloaderService,
outputFile.uri
)
@ -339,8 +341,9 @@ class AnimeDownloaderService : Service() {
DownloadedType(
task.title,
task.episode,
MediaType.ANIME,
)
MediaType.ANIME
),
false
) {}
Injekt.get<CrashlyticsInterface>().logException(
Exception(