Skip to content

Commit

Permalink
修复下载异常, 修复更新对话框意外打开
Browse files Browse the repository at this point in the history
Signed-off-by: 子斗子 <[email protected]>
  • Loading branch information
ZIDOUZI committed Nov 18, 2023
1 parent 530e292 commit f1d6c8f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/zdz/imageURL/model/data/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class Data(
(remote zip local).forEach { (i, j) ->
if (i > j) return true
}
return tagName > version
return false
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/zdz/imageURL/ui/main/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ fun Main(vm: MainViewModel = hiltViewModel(), ctx: Context = LocalContext.curren
suspend fun checkUpdate() = try {
vm.logger.measureTimeMillis("get remove info in %d millis time") {
vm.getData()
}.also { data = it }.isOutOfData()
}.run {
isOutOfData().also { if (it) data = this }
}
} catch (e: Throwable) {
vm.logger.e(e)
null
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/zdz/imageURL/ui/main/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import zdz.libs.preferences.compose.component.functional.Card
import zdz.libs.preferences.compose.delegator
import zdz.libs.preferences.compose.state


@Composable
fun Settings(
queryRoot: () -> Unit,
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/zdz/imageURL/utils/other.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,19 @@ tailrec suspend fun DownloadManager.openAfterFinished(
ctx: Context,
id: Long,
mimeType: String? = null,
duration: Long = 1000
duration: Long = 1000,
cancelIfPaused: Boolean = true,
onFailed: (suspend (Long) -> Unit)? = null
) {
query(id).use {
require(it.moveToFirst())
val status = it.getState()
delay(duration)
if (status == DownloadManager.STATUS_RUNNING) return@use
if (status == DownloadManager.STATUS_SUCCESSFUL) {
ctx.viewContent(
when (status) {
DownloadManager.STATUS_PENDING, DownloadManager.STATUS_RUNNING -> return@use
DownloadManager.STATUS_PAUSED -> if (cancelIfPaused) return
DownloadManager.STATUS_FAILED -> return onFailed?.invoke(id) ?: Unit
DownloadManager.STATUS_SUCCESSFUL -> ctx.viewContent(
getUriForDownloadedFile(id),
mimeType = mimeType ?: getMimeTypeForDownloadedFile(id)
)
Expand Down

0 comments on commit f1d6c8f

Please sign in to comment.