This commit is contained in:
kunfei 2023-01-26 12:26:40 +08:00
parent fe52530be4
commit 5765946d73
5 changed files with 31 additions and 33 deletions

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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?
}
}