This commit is contained in:
tom5079
2020-09-05 12:51:41 +09:00
parent 86d528ba13
commit 081c890b4e
9 changed files with 22 additions and 20 deletions

View File

@@ -113,6 +113,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolderMap[galleryID] = folder.name
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
}
@@ -126,6 +127,7 @@ class DownloadManager private constructor(context: Context) : ContextWrapper(con
downloadFolder.getChild(it).delete()
downloadFolderMap.remove(galleryID)
downloadFolder.getChild(".download").let { if (!it.exists()) it.createNewFile() }
downloadFolder.getChild(".download").writeText(Json.encodeToString(downloadFolderMap))
}
}

View File

@@ -189,7 +189,7 @@ fun checkUpdate(context: Context, force: Boolean = false) {
}
}
fun restore(favorites: GalleryList, url: String, onFailure: ((Exception) -> Unit)? = null, onSuccess: ((List<Int>) -> Unit)? = null) {
fun restore(favorites: GalleryList, url: String, onFailure: ((Throwable) -> Unit)? = null, onSuccess: ((List<Int>) -> Unit)? = null) {
if (!URLUtil.isValidUrl(url)) {
onFailure?.invoke(IllegalArgumentException())
return
@@ -206,10 +206,12 @@ fun restore(favorites: GalleryList, url: String, onFailure: ((Exception) -> Unit
}
override fun onResponse(call: Call, response: Response) {
Json.decodeFromString<List<Int>>(response.body().use { it?.string() } ?: "[]").let {
favorites.addAll(it)
onSuccess?.invoke(it)
}
kotlin.runCatching {
Json.decodeFromString<List<Int>>(response.body().use { it?.string() } ?: "[]").let {
favorites.addAll(it)
onSuccess?.invoke(it)
}
}.onFailure { onFailure?.invoke(it) }
}
})
}