1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-01-31 17:04:59 +01:00

Merge branch 'maintenance' into origin/master

This commit is contained in:
Tlaster 2020-04-17 17:37:15 +08:00
commit 95ec7fc0d2
5 changed files with 54 additions and 30 deletions

View File

@ -17,8 +17,8 @@ allprojects {
ext { ext {
projectGroupId = 'org.mariotaku.twidere' projectGroupId = 'org.mariotaku.twidere'
projectVersionCode = 505 projectVersionCode = 506
projectVersionName = '4.0.6' projectVersionName = '4.0.7'
globalCompileSdkVersion = 29 globalCompileSdkVersion = 29
globalBuildToolsVersion = '29.0.2' globalBuildToolsVersion = '29.0.2'

View File

@ -55,7 +55,7 @@ public interface TwitterUpload {
@Params(@KeyValue(key = "command", value = "APPEND")) @Params(@KeyValue(key = "command", value = "APPEND"))
ResponseCode appendUploadMedia(@Param("media_id") String mediaId, ResponseCode appendUploadMedia(@Param("media_id") String mediaId,
@Param("segment_index") int segmentIndex, @Param("segment_index") int segmentIndex,
@Param("media") Body media) throws MicroBlogException; @Param("media_data") String media) throws MicroBlogException;
@POST("/media/upload.json") @POST("/media/upload.json")
@Params(@KeyValue(key = "command", value = "FINALIZE")) @Params(@KeyValue(key = "command", value = "FINALIZE"))

View File

@ -26,12 +26,13 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.text.TextUtils
import android.util.Base64
import android.util.Log
import android.widget.Toast
import androidx.annotation.UiThread import androidx.annotation.UiThread
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import android.text.TextUtils
import android.util.Log
import android.widget.Toast
import nl.komponents.kovenant.task import nl.komponents.kovenant.task
import nl.komponents.kovenant.ui.successUi import nl.komponents.kovenant.ui.successUi
import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.AbstractTask
@ -43,9 +44,7 @@ import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.twitter.TwitterUpload import org.mariotaku.microblog.library.twitter.TwitterUpload
import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse
import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse.ProcessingInfo import org.mariotaku.microblog.library.twitter.model.MediaUploadResponse.ProcessingInfo
import org.mariotaku.restfu.http.ContentType
import org.mariotaku.restfu.http.mime.Body import org.mariotaku.restfu.http.mime.Body
import org.mariotaku.restfu.http.mime.SimpleBody
import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.TwidereConstants.*
@ -66,7 +65,9 @@ import org.mariotaku.twidere.task.CreateFavoriteTask
import org.mariotaku.twidere.task.RetweetStatusTask import org.mariotaku.twidere.task.RetweetStatusTask
import org.mariotaku.twidere.task.twitter.UpdateStatusTask import org.mariotaku.twidere.task.twitter.UpdateStatusTask
import org.mariotaku.twidere.task.twitter.message.SendMessageTask import org.mariotaku.twidere.task.twitter.message.SendMessageTask
import org.mariotaku.twidere.util.Utils
import org.mariotaku.twidere.util.deleteDrafts import org.mariotaku.twidere.util.deleteDrafts
import java.io.ByteArrayOutputStream
import java.io.IOException import java.io.IOException
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -323,20 +324,26 @@ class LengthyOperationsService : BaseIntentService("lengthy_operations") {
notificationManager.cancel(NOTIFICATION_ID_UPDATE_STATUS) notificationManager.cancel(NOTIFICATION_ID_UPDATE_STATUS)
} }
@Throws(IOException::class, MicroBlogException::class) @Throws(IOException::class, MicroBlogException::class)
private fun uploadMedia(upload: TwitterUpload, body: Body): MediaUploadResponse { private fun uploadMedia(upload: TwitterUpload, body: Body): MediaUploadResponse {
val mediaType = body.contentType().contentType val mediaType = body.contentType().contentType
val length = body.length() val length = body.length()
val stream = body.stream() val stream = body.stream()
var response = upload.initUploadMedia(mediaType, length, null, null) var response = upload.initUploadMedia(mediaType, length, null, null)
val segments = if (length == 0L) 0 else (length / BULK_SIZE + 1).toInt() run {
for (segmentIndex in 0 until segments) { var streamReadLength = 0
val currentBulkSize = Math.min(BULK_SIZE, length - segmentIndex * BULK_SIZE).toInt() var segmentIndex = 0
val bulk = SimpleBody(ContentType.OCTET_STREAM, null, currentBulkSize.toLong(), while (streamReadLength < length) {
stream) val currentBulkSize = Math.min(BULK_SIZE, length - streamReadLength).toInt()
upload.appendUploadMedia(response.id, segmentIndex, bulk) val output = ByteArrayOutputStream()
} Utils.copyStream(stream, output, currentBulkSize)
val data = Base64.encodeToString(output.toByteArray(), Base64.DEFAULT);
upload.appendUploadMedia(response.id, segmentIndex, data)
output.close()
segmentIndex++
streamReadLength += currentBulkSize
}
}
response = upload.finalizeUploadMedia(response.id) response = upload.finalizeUploadMedia(response.id)
run { run {
var info: ProcessingInfo? = response.processingInfo var info: ProcessingInfo? = response.processingInfo

View File

@ -9,11 +9,12 @@ import android.graphics.Point
import android.media.MediaMetadataRetriever import android.media.MediaMetadataRetriever
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.text.TextUtils
import android.util.Base64
import android.webkit.MimeTypeMap
import androidx.annotation.UiThread import androidx.annotation.UiThread
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import androidx.exifinterface.media.ExifInterface import androidx.exifinterface.media.ExifInterface
import android.text.TextUtils
import android.webkit.MimeTypeMap
import net.ypresto.androidtranscoder.MediaTranscoder import net.ypresto.androidtranscoder.MediaTranscoder
import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets
import org.mariotaku.ktextension.* import org.mariotaku.ktextension.*
@ -31,7 +32,6 @@ import org.mariotaku.microblog.library.twitter.model.StatusUpdate
import org.mariotaku.restfu.http.ContentType import org.mariotaku.restfu.http.ContentType
import org.mariotaku.restfu.http.mime.Body import org.mariotaku.restfu.http.mime.Body
import org.mariotaku.restfu.http.mime.FileBody import org.mariotaku.restfu.http.mime.FileBody
import org.mariotaku.restfu.http.mime.SimpleBody
import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.TwidereConstants.*
@ -54,10 +54,7 @@ import org.mariotaku.twidere.util.*
import org.mariotaku.twidere.util.io.ContentLengthInputStream import org.mariotaku.twidere.util.io.ContentLengthInputStream
import org.mariotaku.twidere.util.premium.ExtraFeaturesService import org.mariotaku.twidere.util.premium.ExtraFeaturesService
import org.mariotaku.twidere.util.text.StatusTextValidator import org.mariotaku.twidere.util.text.StatusTextValidator
import java.io.Closeable import java.io.*
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -834,7 +831,6 @@ class UpdateStatusTask(
} }
} }
@Throws(IOException::class, MicroBlogException::class) @Throws(IOException::class, MicroBlogException::class)
private fun uploadMediaChucked(upload: TwitterUpload, body: Body, private fun uploadMediaChucked(upload: TwitterUpload, body: Body,
mediaCategory: String? = null, ownerIds: Array<String>?): MediaUploadResponse { mediaCategory: String? = null, ownerIds: Array<String>?): MediaUploadResponse {
@ -842,12 +838,19 @@ class UpdateStatusTask(
val length = body.length() val length = body.length()
val stream = body.stream() val stream = body.stream()
var response = upload.initUploadMedia(mediaType, length, mediaCategory, ownerIds) var response = upload.initUploadMedia(mediaType, length, mediaCategory, ownerIds)
val segments = if (length == 0L) 0 else (length / BULK_SIZE + 1).toInt() run {
for (segmentIndex in 0 until segments) { var streamReadLength = 0
val currentBulkSize = Math.min(BULK_SIZE.toLong(), length - segmentIndex * BULK_SIZE).toInt() var segmentIndex = 0
val bulk = SimpleBody(ContentType.OCTET_STREAM, null, currentBulkSize.toLong(), while (streamReadLength < length) {
stream) val currentBulkSize = Math.min(BULK_SIZE.toLong(), length - streamReadLength).toInt()
upload.appendUploadMedia(response.id, segmentIndex, bulk) val output = ByteArrayOutputStream()
Utils.copyStream(stream, output, currentBulkSize)
val data = Base64.encodeToString(output.toByteArray(), Base64.DEFAULT);
upload.appendUploadMedia(response.id, segmentIndex, data)
output.close()
segmentIndex++
streamReadLength += currentBulkSize
}
} }
response = upload.finalizeUploadMedia(response.id) response = upload.finalizeUploadMedia(response.id)
var info: MediaUploadResponse.ProcessingInfo? = response.processingInfo var info: MediaUploadResponse.ProcessingInfo? = response.processingInfo

View File

@ -89,6 +89,8 @@ import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
import org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_IMAGES import org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_IMAGES
import org.mariotaku.twidere.view.TabPagerIndicator import org.mariotaku.twidere.view.TabPagerIndicator
import java.io.File import java.io.File
import java.io.InputStream
import java.io.OutputStream
import java.util.* import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
@ -607,4 +609,16 @@ object Utils {
} }
fun copyStream(input: InputStream, output: OutputStream, length: Int) {
val buffer = ByteArray(1024)
var bytesRead: Int = 0
do {
val read = input.read(buffer)
if (read == -1) {
break
}
output.write(buffer, 0, read)
bytesRead += read
} while (bytesRead <= length)
}
} }