mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-02 09:46:51 +01:00
fixed #942
This commit is contained in:
parent
302180b95b
commit
639b01a7e5
@ -1091,29 +1091,24 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
} else {
|
||||
hasAccountKeys = false
|
||||
}
|
||||
if (Intent.ACTION_SEND == action) {
|
||||
shouldSaveAccounts = false
|
||||
shouldSaveVisibility = false
|
||||
val stream = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
|
||||
if (stream != null) {
|
||||
val src = arrayOf(stream)
|
||||
TaskStarter.execute(AddMediaTask(this, src, null, true, false))
|
||||
when (action) {
|
||||
Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE -> {
|
||||
shouldSaveAccounts = false
|
||||
shouldSaveVisibility = false
|
||||
val stream = intent.getStreamExtra()
|
||||
if (stream != null) {
|
||||
val src = stream.toTypedArray()
|
||||
TaskStarter.execute(AddMediaTask(this, src, null, true, false))
|
||||
}
|
||||
}
|
||||
} else if (Intent.ACTION_SEND_MULTIPLE == action) {
|
||||
shouldSaveAccounts = false
|
||||
shouldSaveVisibility = false
|
||||
val extraStream = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
|
||||
if (extraStream != null) {
|
||||
val src = extraStream.toTypedArray()
|
||||
TaskStarter.execute(AddMediaTask(this, src, null, true, false))
|
||||
}
|
||||
} else {
|
||||
shouldSaveAccounts = !hasAccountKeys
|
||||
shouldSaveVisibility = !hasVisibility
|
||||
val data = intent.data
|
||||
if (data != null) {
|
||||
val src = arrayOf(data)
|
||||
TaskStarter.execute(AddMediaTask(this, src, null, true, false))
|
||||
else -> {
|
||||
shouldSaveAccounts = !hasAccountKeys
|
||||
shouldSaveVisibility = !hasVisibility
|
||||
val data = intent.data
|
||||
if (data != null) {
|
||||
val src = arrayOf(data)
|
||||
TaskStarter.execute(AddMediaTask(this, src, null, true, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
val extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT)
|
||||
@ -2222,6 +2217,13 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||
it.visibility = visibility
|
||||
}
|
||||
|
||||
private fun Intent.getStreamExtra(): List<Uri>? {
|
||||
val list = getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
|
||||
if (list != null) return list
|
||||
val item = getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
|
||||
if (item != null) return listOf(item)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package org.mariotaku.twidere.app
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.accounts.OnAccountsUpdateListener
|
||||
import android.app.Application
|
||||
import android.content.*
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||
@ -39,6 +41,7 @@ import org.mariotaku.commons.logansquare.LoganSquareMapperFinder
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.kpreferences.set
|
||||
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
|
||||
import org.mariotaku.ktextension.isCurrentThreadCompat
|
||||
import org.mariotaku.ktextension.setLayoutDirectionCompat
|
||||
import org.mariotaku.mediaviewer.library.MediaDownloader
|
||||
@ -165,7 +168,9 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
||||
Analyzer.preferencesChanged(sharedPreferences)
|
||||
DataSyncProvider.Factory.notifyUpdate(this)
|
||||
|
||||
NotificationChannelsManager.updateAccountChannelsAndGroups(this)
|
||||
AccountManager.get(this).addOnAccountsUpdatedListenerSafe(OnAccountsUpdateListener {
|
||||
NotificationChannelsManager.updateAccountChannelsAndGroups(this)
|
||||
}, updateImmediately = true)
|
||||
}
|
||||
|
||||
|
||||
@ -344,10 +349,6 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateAccountNotificationGroup() {
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val KEY_UCD_DATA_PROFILING = "ucd_data_profiling"
|
||||
|
@ -49,12 +49,14 @@ open class AbsAddMediaTask<Callback>(
|
||||
var st: InputStream? = null
|
||||
var os: OutputStream? = null
|
||||
try {
|
||||
val sourceMimeType = resolver.getType(source)
|
||||
val mimeTypeMap = MimeTypeMap.getSingleton()
|
||||
val sourceMimeType = resolver.getType(source) ?: mimeTypeMap.getMimeTypeFromExtension(
|
||||
source.lastPathSegment.substringAfterLast('.', "tmp"))
|
||||
val mediaType = types?.get(index) ?: sourceMimeType?.let {
|
||||
return@let inferMediaType(it)
|
||||
} ?: ParcelableMedia.Type.IMAGE
|
||||
val extension = sourceMimeType?.let { mimeType ->
|
||||
MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType)
|
||||
mimeTypeMap.getExtensionFromMimeType(mimeType)
|
||||
} ?: "tmp"
|
||||
st = resolver.openInputStream(source) ?: throw FileNotFoundException("Unable to open $source")
|
||||
val destination: Uri
|
||||
|
@ -714,10 +714,10 @@ class UpdateStatusTask(
|
||||
ContentLengthInputStream.ReadListener { length, position ->
|
||||
callback?.onUploadingProgressChanged(index, position, length)
|
||||
})
|
||||
if (chucked) {
|
||||
resp = uploadMediaChucked(upload, body.body, mediaCategory, ownerIds)
|
||||
resp = if (chucked) {
|
||||
uploadMediaChucked(upload, body.body, mediaCategory, ownerIds)
|
||||
} else {
|
||||
resp = upload.uploadMedia(body.body, ownerIds)
|
||||
upload.uploadMedia(body.body, ownerIds)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
throw UploadException(e).apply {
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package org.mariotaku.twidere.util.net
|
||||
|
||||
import okhttp3.ConnectionSpec
|
||||
import okhttp3.internal.Internal
|
||||
import java.io.IOException
|
||||
import java.net.InetAddress
|
||||
import java.net.Socket
|
||||
@ -31,55 +33,54 @@ import javax.net.ssl.SSLSocketFactory
|
||||
*/
|
||||
class TLSSocketFactory : SSLSocketFactory() {
|
||||
|
||||
private val internalSSLSocketFactory: SSLSocketFactory
|
||||
private val delegate: SSLSocketFactory
|
||||
|
||||
init {
|
||||
val context = SSLContext.getInstance("TLS")
|
||||
context.init(null, null, null)
|
||||
internalSSLSocketFactory = context.socketFactory
|
||||
val context = SSLContext.getInstance("TLS").apply {
|
||||
init(null, null, null)
|
||||
}
|
||||
delegate = context.socketFactory
|
||||
}
|
||||
|
||||
override fun getDefaultCipherSuites(): Array<String> {
|
||||
return internalSSLSocketFactory.defaultCipherSuites
|
||||
return delegate.defaultCipherSuites
|
||||
}
|
||||
|
||||
override fun getSupportedCipherSuites(): Array<String> {
|
||||
return internalSSLSocketFactory.supportedCipherSuites
|
||||
return delegate.supportedCipherSuites
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
|
||||
return internalSSLSocketFactory.createSocket(s, host, port, autoClose).applyTLS()
|
||||
return delegate.createSocket(s, host, port, autoClose).applyTLS()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun createSocket(host: String, port: Int): Socket {
|
||||
return internalSSLSocketFactory.createSocket(host, port).applyTLS()
|
||||
return delegate.createSocket(host, port).applyTLS()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun createSocket(host: String, port: Int, localHost: InetAddress, localPort: Int): Socket {
|
||||
return internalSSLSocketFactory.createSocket(host, port, localHost, localPort).applyTLS()
|
||||
return delegate.createSocket(host, port, localHost, localPort).applyTLS()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun createSocket(host: InetAddress, port: Int): Socket {
|
||||
return internalSSLSocketFactory.createSocket(host, port).applyTLS()
|
||||
return delegate.createSocket(host, port).applyTLS()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun createSocket(address: InetAddress, port: Int, localAddress: InetAddress, localPort: Int): Socket {
|
||||
return internalSSLSocketFactory.createSocket(address, port, localAddress, localPort).applyTLS()
|
||||
return delegate.createSocket(address, port, localAddress, localPort).applyTLS()
|
||||
}
|
||||
|
||||
private fun Socket.applyTLS(): Socket {
|
||||
if (this is SSLSocket) {
|
||||
enabledProtocols = this.supportedProtocols.intersect(tlsProtocols).toTypedArray()
|
||||
}
|
||||
if (this !is SSLSocket) return this
|
||||
this.enabledProtocols = this.supportedProtocols
|
||||
this.enabledCipherSuites = this.enabledCipherSuites
|
||||
Internal.instance.apply(ConnectionSpec.MODERN_TLS, this, false)
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val tlsProtocols = listOf("TLSv1.2", "TLSv1.1", "TLSv1")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user