fixed gif upload

This commit is contained in:
Mariotaku Lee 2016-08-24 00:24:51 +08:00
parent d1212e8893
commit 482c99cb4f
2 changed files with 22 additions and 16 deletions

View File

@ -35,8 +35,8 @@ android {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 24
versionCode 206
versionName '3.2.2'
versionCode 207
versionName '3.2.3'
multiDexEnabled true
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("false")'

View File

@ -671,23 +671,29 @@ class UpdateStatusTask(
o.inSampleSize = Utils.calculateInSampleSize(o.outWidth, o.outHeight,
sizeLimit.x, sizeLimit.y)
o.inJustDecodeBounds = false
val bitmap = BitmapFactoryUtils.decodeUri(resolver, mediaUri, null, o)
if (bitmap != null && mediaType != "image/gif") {
val os = DirectByteArrayOutputStream()
when (mediaType) {
"image/png", "image/x-png", "image/webp", "image-x-webp" -> {
bitmap.compress(Bitmap.CompressFormat.PNG, 0, os)
}
else -> {
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, os)
}
}
length = os.size().toLong()
cis = ContentLengthInputStream(os.inputStream(true), length)
} else {
if (mediaType == "image/gif") {
val st = resolver.openInputStream(mediaUri) ?: throw FileNotFoundException(mediaUri.toString())
length = st.available().toLong()
cis = ContentLengthInputStream(st, length)
} else {
val bitmap = BitmapFactoryUtils.decodeUri(resolver, mediaUri, null, o)
if (bitmap != null) {
val os = DirectByteArrayOutputStream()
when (mediaType) {
"image/png", "image/x-png", "image/webp", "image-x-webp" -> {
bitmap.compress(Bitmap.CompressFormat.PNG, 0, os)
}
else -> {
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, os)
}
}
length = os.size().toLong()
cis = ContentLengthInputStream(os.inputStream(true), length)
} else {
val st = resolver.openInputStream(mediaUri) ?: throw FileNotFoundException(mediaUri.toString())
length = st.available().toLong()
cis = ContentLengthInputStream(st, length)
}
}
} else {
val st = resolver.openInputStream(mediaUri) ?: throw FileNotFoundException(mediaUri.toString())