Suspend DownloadDirnameDao deleteByKey

This commit is contained in:
tarsin committed 2023-07-12 09:35:32 +08:00
1 parent 3f53710c5b
commit 62c3e9290e
4 files changed
+12 -13

No files matched your search

+1 -2
View File
@@ -88,8 +88,7 @@ object EhDB {
}
}
@Synchronized
fun removeDownloadDirname(gid: Long) {
suspend fun removeDownloadDirname(gid: Long) {
val dao = db.downloadDirnameDao()
dao.deleteByKey(gid)
}
@@ -17,7 +17,7 @@ interface DownloadDirnameDao {
fun insert(t: DownloadDirname): Long
@Query("DELETE FROM DOWNLOAD_DIRNAME WHERE GID = :gid")
fun deleteByKey(gid: Long)
suspend fun deleteByKey(gid: Long)
@Query("SELECT * FROM DOWNLOAD_DIRNAME")
fun list(): List<DownloadDirname>
@@ -774,15 +774,15 @@ class DownloadsScene :
val checked = mBuilder.isChecked
Settings.removeImageFiles = checked
if (checked) {
val files = arrayOfNulls<UniFile>(mDownloadInfoList.size)
for ((i, info) in mDownloadInfoList.withIndex()) {
// Put file
files[i] = SpiderDen.getGalleryDownloadDir(info.gid)
// Remove download path
EhDB.removeDownloadDirname(info.gid)
}
// Delete file
lifecycleScope.launchIO {
val files = arrayOfNulls<UniFile>(mDownloadInfoList.size)
for ((i, info) in mDownloadInfoList.withIndex()) {
// Put file
files[i] = SpiderDen.getGalleryDownloadDir(info.gid)
// Remove download path
EhDB.removeDownloadDirname(info.gid)
}
// Delete file
files.forEach { it?.delete() }
}
}
@@ -1271,10 +1271,10 @@ class GalleryDetailScene : BaseScene() {
val checked = mBuilder.isChecked
Settings.removeImageFiles = checked
if (checked) {
val file = SpiderDen.getGalleryDownloadDir(mGalleryInfo.gid)
EhDB.removeDownloadDirname(mGalleryInfo.gid)
lifecycleScope.launchIO {
runCatching {
val file = SpiderDen.getGalleryDownloadDir(mGalleryInfo.gid)
EhDB.removeDownloadDirname(mGalleryInfo.gid)
file?.delete()
}
}