diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt index e6abd1eca..f7248dc91 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -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(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(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? { + val list = getParcelableArrayListExtra(Intent.EXTRA_STREAM) + if (list != null) return list + val item = getParcelableExtra(Intent.EXTRA_STREAM) + if (item != null) return listOf(item) + return null + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt index 121c10e87..5f8b3d4ee 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt @@ -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" diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt index 83fb1b3a7..4a135f6cc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/compose/AbsAddMediaTask.kt @@ -49,12 +49,14 @@ open class AbsAddMediaTask( 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 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt index 464d87be3..565190668 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/UpdateStatusTask.kt @@ -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 { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TLSSocketFactory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TLSSocketFactory.kt index 5d5574714..fc1bfc6b3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TLSSocketFactory.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TLSSocketFactory.kt @@ -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 { - return internalSSLSocketFactory.defaultCipherSuites + return delegate.defaultCipherSuites } override fun getSupportedCipherSuites(): Array { - 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") - } } \ No newline at end of file