fix: check for empty uri
This commit is contained in:
parent
95c0b574b0
commit
dc19694d68
1 changed files with 24 additions and 15 deletions
|
@ -141,13 +141,18 @@ class DownloadsManager(private val context: Context) {
|
||||||
newUri: Uri,
|
newUri: Uri,
|
||||||
finished: (Boolean, String) -> Unit
|
finished: (Boolean, String) -> Unit
|
||||||
) {
|
) {
|
||||||
try {
|
|
||||||
if (oldUri == newUri) {
|
if (oldUri == newUri) {
|
||||||
|
Logger.log("Source and destination are the same")
|
||||||
finished(false, "Source and destination are the same")
|
finished(false, "Source and destination are the same")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (oldUri == Uri.EMPTY) {
|
||||||
|
Logger.log("Old Uri is empty")
|
||||||
|
finished(true, "Old Uri is empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
val oldBase =
|
val oldBase =
|
||||||
DocumentFile.fromTreeUri(context, oldUri) ?: throw Exception("Old base is null")
|
DocumentFile.fromTreeUri(context, oldUri) ?: throw Exception("Old base is null")
|
||||||
val newBase =
|
val newBase =
|
||||||
|
@ -199,13 +204,17 @@ class DownloadsManager(private val context: Context) {
|
||||||
finished(true, "Successfully moved downloads")
|
finished(true, "Successfully moved downloads")
|
||||||
super.onCompleted(result)
|
super.onCompleted(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
snackString("Error: ${e.message}")
|
snackString("Error: ${e.message}")
|
||||||
|
Logger.log("Failed to move downloads: ${e.message}")
|
||||||
|
Logger.log(e)
|
||||||
|
Logger.log("oldUri: $oldUri, newUri: $newUri")
|
||||||
finished(false, "Failed to move downloads: ${e.message}")
|
finished(false, "Failed to move downloads: ${e.message}")
|
||||||
return
|
return@launch
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +392,7 @@ data class DownloadedType(
|
||||||
private val chapter: String? = null
|
private val chapter: String? = null
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
val titleName: String
|
val titleName: String
|
||||||
get() = title?:pTitle.findValidName()
|
get() = title ?: pTitle.findValidName()
|
||||||
val chapterName: String
|
val chapterName: String
|
||||||
get() = chapter?:pChapter.findValidName()
|
get() = chapter ?: pChapter.findValidName()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue