From c5c0c6c4bdf6cb0e81c8e075ec2b9e6a7fa6f4b8 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:14:16 +0800 Subject: [PATCH] Initial support for third-party download manager --- .../ehviewer/ui/screen/GalleryDetailScreen.kt | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt index 72e65801a..8eceba7db 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailScreen.kt @@ -2,6 +2,8 @@ package com.hippo.ehviewer.ui.screen import android.Manifest import android.app.DownloadManager +import android.content.ActivityNotFoundException +import android.content.Intent import android.net.Uri import android.os.Environment import android.os.Parcelable @@ -346,14 +348,24 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa val res = mArchiveList!![selected].res val isHAtH = mArchiveList!![selected].isHAtH EhEngine.downloadArchive(gid, token, mArchiveFormParamOr!!, res, isHAtH)?.let { - val r = DownloadManager.Request(Uri.parse(it)) + val uri = Uri.parse(it) + val intent = Intent().apply { + action = Intent.ACTION_VIEW + setDataAndType(uri, "application/zip") + } val name = "$gid-${EhUtils.getSuitableTitle(galleryDetail)}.zip" - r.setDestinationInExternalPublicDir( - Environment.DIRECTORY_DOWNLOADS, - AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name), - ) - r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) - downloadManager.enqueue(r) + try { + activity.startActivity(intent) + context.addTextToClipboard(name, true) + } catch (_: ActivityNotFoundException) { + val r = DownloadManager.Request(uri) + r.setDestinationInExternalPublicDir( + Environment.DIRECTORY_DOWNLOADS, + AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name), + ) + r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) + downloadManager.enqueue(r) + } } activity.showTip(R.string.download_archive_started) }