コード整形
This commit is contained in:
parent
1f8606b241
commit
e7bbae83af
|
@ -50,7 +50,8 @@ class TestTootInstance {
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private val dummyClientCallback = object : TootApiCallback {
|
private val dummyClientCallback = object : TootApiCallback {
|
||||||
override val isApiCancelled: Boolean = false
|
override suspend fun isApiCancelled() = false
|
||||||
|
|
||||||
override suspend fun publishApiProgress(s: String) {
|
override suspend fun publishApiProgress(s: String) {
|
||||||
log.d("apiProgress: $s")
|
log.d("apiProgress: $s")
|
||||||
}
|
}
|
||||||
|
@ -83,7 +84,6 @@ class TestTootInstance {
|
||||||
assertNotNull(ti)
|
assertNotNull(ti)
|
||||||
assertNull(ri?.error)
|
assertNull(ri?.error)
|
||||||
ti!!.run { log.d("$instanceType $uri $version") }
|
ti!!.run { log.d("$instanceType $uri $version") }
|
||||||
|
|
||||||
}
|
}
|
||||||
a(Host.parse("mastodon.juggler.jp"))
|
a(Host.parse("mastodon.juggler.jp"))
|
||||||
a(Host.parse("misskey.io"))
|
a(Host.parse("misskey.io"))
|
||||||
|
@ -106,4 +106,4 @@ class TestTootInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,17 +9,16 @@ import javax.net.ssl.*
|
||||||
|
|
||||||
object MySslSocketFactory : SSLSocketFactory() {
|
object MySslSocketFactory : SSLSocketFactory() {
|
||||||
|
|
||||||
private var debugCipherSuites = false
|
|
||||||
|
|
||||||
private val log = LogCategory("MySslSocketFactory")
|
private val log = LogCategory("MySslSocketFactory")
|
||||||
|
|
||||||
|
private var debugCipherSuites = false
|
||||||
|
|
||||||
private val originalFactory: SSLSocketFactory =
|
private val originalFactory: SSLSocketFactory =
|
||||||
SSLContext.getInstance("TLS").apply {
|
SSLContext.getInstance("TLS").apply {
|
||||||
init(null, null, null)
|
init(null, null, null)
|
||||||
}.socketFactory
|
}.socketFactory
|
||||||
|
|
||||||
private fun check(socket: Socket?): Socket? {
|
private fun check(socket: Socket?): Socket? {
|
||||||
|
|
||||||
// 端末のデフォルトでは1.3が含まれないので追加する
|
// 端末のデフォルトでは1.3が含まれないので追加する
|
||||||
(socket as? SSLSocket)?.enabledProtocols = arrayOf("TLSv1.1", "TLSv1.2", "TLSv1.3")
|
(socket as? SSLSocket)?.enabledProtocols = arrayOf("TLSv1.1", "TLSv1.2", "TLSv1.3")
|
||||||
|
|
||||||
|
@ -34,85 +33,93 @@ object MySslSocketFactory : SSLSocketFactory() {
|
||||||
return socket
|
return socket
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDefaultCipherSuites(): Array<String> {
|
override fun getDefaultCipherSuites(): Array<String> =
|
||||||
return originalFactory.defaultCipherSuites
|
originalFactory.defaultCipherSuites
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSupportedCipherSuites(): Array<String> {
|
override fun getSupportedCipherSuites(): Array<String> =
|
||||||
return originalFactory.supportedCipherSuites
|
originalFactory.supportedCipherSuites
|
||||||
}
|
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createSocket(): Socket? {
|
override fun createSocket(
|
||||||
return check(originalFactory.createSocket())
|
): Socket? = check(
|
||||||
}
|
originalFactory.createSocket()
|
||||||
|
)
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket? {
|
override fun createSocket(
|
||||||
return check(
|
s: Socket,
|
||||||
originalFactory.createSocket(
|
host: String,
|
||||||
s,
|
port: Int,
|
||||||
host,
|
autoClose: Boolean,
|
||||||
port,
|
): Socket? = check(
|
||||||
autoClose
|
originalFactory.createSocket(
|
||||||
)
|
s,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
autoClose
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
@Throws(IOException::class, UnknownHostException::class)
|
@Throws(IOException::class, UnknownHostException::class)
|
||||||
override fun createSocket(host: String, port: Int): Socket? {
|
override fun createSocket(
|
||||||
return check(
|
host: String,
|
||||||
originalFactory.createSocket(
|
port: Int,
|
||||||
host,
|
): Socket? = check(
|
||||||
port
|
originalFactory.createSocket(
|
||||||
)
|
host,
|
||||||
|
port
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
@Throws(IOException::class, UnknownHostException::class)
|
@Throws(IOException::class, UnknownHostException::class)
|
||||||
override fun createSocket(host: String, port: Int, localHost: InetAddress, localPort: Int): Socket? {
|
override fun createSocket(
|
||||||
return check(
|
host: String,
|
||||||
originalFactory.createSocket(
|
port: Int,
|
||||||
host,
|
localHost: InetAddress,
|
||||||
port,
|
localPort: Int,
|
||||||
localHost,
|
): Socket? = check(
|
||||||
localPort
|
originalFactory.createSocket(
|
||||||
)
|
host,
|
||||||
|
port,
|
||||||
|
localHost,
|
||||||
|
localPort
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createSocket(host: InetAddress, port: Int): Socket? {
|
override fun createSocket(
|
||||||
return check(
|
host: InetAddress,
|
||||||
originalFactory.createSocket(
|
port: Int,
|
||||||
host,
|
): Socket? = check(
|
||||||
port
|
originalFactory.createSocket(
|
||||||
)
|
host,
|
||||||
|
port
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createSocket(address: InetAddress, port: Int, localAddress: InetAddress, localPort: Int): Socket? {
|
override fun createSocket(
|
||||||
return check(
|
address: InetAddress,
|
||||||
originalFactory.createSocket(
|
port: Int,
|
||||||
address,
|
localAddress: InetAddress,
|
||||||
port,
|
localPort: Int,
|
||||||
localAddress,
|
): Socket? = check(
|
||||||
localPort
|
originalFactory.createSocket(
|
||||||
)
|
address,
|
||||||
|
port,
|
||||||
|
localAddress,
|
||||||
|
localPort
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
|
|
||||||
//
|
// App1, TestTootInstance 等で使われる
|
||||||
val trustManager: X509TrustManager by lazy {
|
val trustManager: X509TrustManager by lazy {
|
||||||
val trustManagers = TrustManagerFactory
|
val list = TrustManagerFactory
|
||||||
.getInstance(TrustManagerFactory.getDefaultAlgorithm())
|
.getInstance(TrustManagerFactory.getDefaultAlgorithm())
|
||||||
.apply { init(null as KeyStore?) }
|
.apply { init(null as KeyStore?) }
|
||||||
.trustManagers
|
.trustManagers
|
||||||
|
|
||||||
trustManagers
|
list?.firstNotNullOfOrNull { it as? X509TrustManager }
|
||||||
.find { it is X509TrustManager }
|
?: error("missing X509TrustManager in $list")
|
||||||
as? X509TrustManager
|
|
||||||
?: error("missing X509TrustManager in $trustManagers")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,7 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import jp.juggler.subwaytooter.R
|
import jp.juggler.subwaytooter.R
|
||||||
|
|
||||||
object UiUtils {
|
private val log = LogCategory("UiUtils")
|
||||||
|
|
||||||
val log = LogCategory("UiUtils")
|
|
||||||
}
|
|
||||||
|
|
||||||
// colorARGB.applyAlphaMultiplier(0.5f) でalpha値が半分になったARGB値を得る
|
// colorARGB.applyAlphaMultiplier(0.5f) でalpha値が半分になったARGB値を得る
|
||||||
fun Int.applyAlphaMultiplier(alphaMultiplier: Float? = null): Int {
|
fun Int.applyAlphaMultiplier(alphaMultiplier: Float? = null): Int {
|
||||||
|
@ -96,12 +93,11 @@ fun createRoundDrawable(
|
||||||
fillColor: Int? = null,
|
fillColor: Int? = null,
|
||||||
strokeColor: Int? = null,
|
strokeColor: Int? = null,
|
||||||
strokeWidth: Int = 4,
|
strokeWidth: Int = 4,
|
||||||
) =
|
) = GradientDrawable().apply {
|
||||||
GradientDrawable().apply {
|
cornerRadius = radius
|
||||||
cornerRadius = radius
|
if (fillColor != null) setColor(fillColor)
|
||||||
if (fillColor != null) setColor(fillColor)
|
if (strokeColor != null) setStroke(strokeWidth, strokeColor)
|
||||||
if (strokeColor != null) setStroke(strokeWidth, strokeColor)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 色を指定してRippleDrawableを生成する
|
// 色を指定してRippleDrawableを生成する
|
||||||
fun getAdaptiveRippleDrawable(normalColor: Int, pressedColor: Int): Drawable {
|
fun getAdaptiveRippleDrawable(normalColor: Int, pressedColor: Int): Drawable {
|
||||||
|
@ -296,7 +292,7 @@ fun CharSequence.copyToClipboard(context: Context) {
|
||||||
|
|
||||||
context.showToast(false, R.string.copy_complete)
|
context.showToast(false, R.string.copy_complete)
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
UiUtils.log.e(ex, "copy failed.")
|
log.e(ex, "copy failed.")
|
||||||
context.showToast(ex, "copy failed.")
|
context.showToast(ex, "copy failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue