From 5765946d73ae50559d388b6da1fe7ad2fe4933ae Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 26 Jan 2023 12:26:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/AppIntentType.kt | 17 +++++++++++ .../java/io/legado/app/help/IntentType.kt | 28 ------------------- .../io/legado/app/service/DownloadService.kt | 2 +- .../io/legado/app/utils/ContextExtensions.kt | 1 - .../java/io/legado/app/utils}/IntentType.kt | 16 +++++++++-- 5 files changed, 31 insertions(+), 33 deletions(-) create mode 100644 app/src/app/java/io/legado/app/help/AppIntentType.kt delete mode 100644 app/src/google/java/io/legado/app/help/IntentType.kt rename app/src/{app/java/io/legado/app/help => main/java/io/legado/app/utils}/IntentType.kt (64%) diff --git a/app/src/app/java/io/legado/app/help/AppIntentType.kt b/app/src/app/java/io/legado/app/help/AppIntentType.kt new file mode 100644 index 000000000..2d20cda36 --- /dev/null +++ b/app/src/app/java/io/legado/app/help/AppIntentType.kt @@ -0,0 +1,17 @@ +package io.legado.app.help + +import androidx.annotation.Keep +import io.legado.app.utils.IntentType + +@Keep +@Suppress("unused") +object AppIntentType : IntentType.TypeInterface { + + override fun from(path: String?): String? { + return when (path?.substringAfterLast(".")?.lowercase()) { + "apk" -> "application/vnd.android.package-archive" + else -> null + } + } + +} \ No newline at end of file diff --git a/app/src/google/java/io/legado/app/help/IntentType.kt b/app/src/google/java/io/legado/app/help/IntentType.kt deleted file mode 100644 index d884120e5..000000000 --- a/app/src/google/java/io/legado/app/help/IntentType.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.legado.app.help - -import android.net.Uri -import androidx.annotation.Keep -import java.io.File - -@Keep -object IntentType { - - fun from(uri: Uri): String? { - return from(uri.toString()) - } - - fun from(file: File): String? { - return from(file.absolutePath) - } - - fun from(path: String?): String? { - return when (path?.substringAfterLast(".")?.lowercase()) { - "m4a", "mp3", "mid", "xmf", "ogg", "wav" -> "video/*" - "3gp", "mp4" -> "audio/*" - "jpg", "gif", "png", "jpeg", "bmp" -> "image/*" - "txt", "json" -> "text/plain" - else -> null - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index e130dbaed..d2da985f6 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -13,7 +13,7 @@ import io.legado.app.base.BaseService import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.constant.IntentAction -import io.legado.app.help.IntentType +import io.legado.app.utils.IntentType import io.legado.app.utils.openFileUri import io.legado.app.utils.servicePendingIntent import io.legado.app.utils.toastOnUi diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index c902805e5..9ecf84e99 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -29,7 +29,6 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.help.IntentHelp -import io.legado.app.help.IntentType import splitties.systemservices.clipboardManager import splitties.systemservices.connectivityManager import java.io.File diff --git a/app/src/app/java/io/legado/app/help/IntentType.kt b/app/src/main/java/io/legado/app/utils/IntentType.kt similarity index 64% rename from app/src/app/java/io/legado/app/help/IntentType.kt rename to app/src/main/java/io/legado/app/utils/IntentType.kt index ff2d0632d..59ac3a60c 100644 --- a/app/src/app/java/io/legado/app/help/IntentType.kt +++ b/app/src/main/java/io/legado/app/utils/IntentType.kt @@ -1,4 +1,4 @@ -package io.legado.app.help +package io.legado.app.utils import android.net.Uri import androidx.annotation.Keep @@ -17,13 +17,23 @@ object IntentType { fun from(path: String?): String? { return when (path?.substringAfterLast(".")?.lowercase()) { - "apk" -> "application/vnd.android.package-archive" "m4a", "mp3", "mid", "xmf", "ogg", "wav" -> "video/*" "3gp", "mp4" -> "audio/*" "jpg", "gif", "png", "jpeg", "bmp" -> "image/*" "txt", "json" -> "text/plain" - else -> null + else -> appIntentType?.from(path) } } + private val appIntentType: TypeInterface? by lazy { + Class.forName("io.legado.app.help.AppIntentType") + .kotlin.objectInstance as? TypeInterface + } + + interface TypeInterface { + + fun from(path: String?): String? + + } + } \ No newline at end of file