MimeTypeMap is case-sensitive prior to Android O
https://android-review.googlesource.com/251120
This commit is contained in:
1 parent
df1efa7604
commit
fe0c74de23
6 files changed
+8
-20
No files matched your search
@@ -62,7 +62,7 @@ abstract class PageLoader2(private val gid: Long, var startPage: Int) : PageLoad
|
||||
protected abstract fun getImageExtension(index: Int): String
|
||||
|
||||
fun getImageFilename(index: Int): String {
|
||||
return "$title - ${index + 1}.${getImageExtension(index)}"
|
||||
return "$title - ${index + 1}.${getImageExtension(index).lowercase()}"
|
||||
}
|
||||
|
||||
abstract fun save(index: Int, file: UniFile): Boolean
|
||||
|
||||
@@ -76,7 +76,7 @@ fun GalleryInfo.getComicInfo(): ComicInfo {
|
||||
}
|
||||
return ComicInfo(
|
||||
series = title,
|
||||
alternateSeries = titleJpn.takeUnless { it.isNullOrBlank() },
|
||||
alternateSeries = titleJpn?.ifBlank { null },
|
||||
writer = groups.ifEmpty { null },
|
||||
penciller = artists.ifEmpty { null },
|
||||
genre = otherTags.ifEmpty { null },
|
||||
|
||||
@@ -169,7 +169,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
|
||||
userAgent = dialogState.awaitInputText(
|
||||
initial = userAgent,
|
||||
title = userAgentTitle,
|
||||
).trim().takeUnless { it.isBlank() } ?: CHROME_USER_AGENT
|
||||
).trim().ifBlank { null } ?: CHROME_USER_AGENT
|
||||
}
|
||||
}
|
||||
val exportFailed = stringResource(id = R.string.settings_advanced_export_data_failed)
|
||||
|
||||
@@ -129,7 +129,7 @@ object FileUtils {
|
||||
* @return null for can't find extension
|
||||
*/
|
||||
fun getExtensionFromFilename(filename: String?) =
|
||||
filename?.substringAfterLast('.', "").takeUnless { it.isNullOrEmpty() }
|
||||
filename?.substringAfterLast('.', "")?.ifEmpty { null }
|
||||
|
||||
/**
|
||||
* Get name from filename
|
||||
@@ -138,7 +138,7 @@ object FileUtils {
|
||||
* @return null for start with . dot
|
||||
*/
|
||||
fun getNameFromFilename(filename: String?) =
|
||||
filename?.substringBeforeLast('.').takeUnless { it.isNullOrEmpty() }
|
||||
filename?.substringBeforeLast('.')?.ifEmpty { null }
|
||||
|
||||
/**
|
||||
* Create a temp file, you need to delete it by you self.
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.os.ParcelFileDescriptor.open
|
||||
import android.os.ParcelFileDescriptor.parseMode
|
||||
import android.webkit.MimeTypeMap
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
class RawFile(override val parent: RawFile?, private var file: File) : UniFile {
|
||||
|
||||
@@ -71,7 +70,8 @@ class RawFile(override val parent: RawFile?, private var file: File) : UniFile {
|
||||
get() = if (file.isDirectory) {
|
||||
null
|
||||
} else {
|
||||
getTypeForName(file.name)
|
||||
val extension = file.extension.ifEmpty { null }?.lowercase()
|
||||
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) ?: "application/octet-stream"
|
||||
}
|
||||
override val isDirectory: Boolean
|
||||
get() = file.isDirectory
|
||||
@@ -130,15 +130,3 @@ class RawFile(override val parent: RawFile?, private var file: File) : UniFile {
|
||||
|
||||
override fun openFileDescriptor(mode: String): ParcelFileDescriptor = open(file, parseMode(mode))
|
||||
}
|
||||
|
||||
private fun getTypeForName(name: String): String {
|
||||
val lastDot = name.lastIndexOf('.')
|
||||
if (lastDot >= 0) {
|
||||
val extension = name.substring(lastDot + 1).lowercase(Locale.getDefault())
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
if (mime != null) {
|
||||
return mime
|
||||
}
|
||||
}
|
||||
return "application/octet-stream"
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class TreeDocumentFile(
|
||||
if (child != null) {
|
||||
if (child.isFile) return child
|
||||
} else {
|
||||
val extension = displayName.substringAfterLast('.', "")
|
||||
val extension = displayName.substringAfterLast('.', "").ifEmpty { null }?.lowercase()
|
||||
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) ?: "application/octet-stream"
|
||||
val result = DocumentsContractApi21.createFile(uri, mimeType, displayName)
|
||||
if (result != null) {
|
||||
|
||||
Reference in new issue
Block a user