fix bad padding on scrollbars

This commit is contained in:
Jonathan Fisher 2020-11-15 20:51:13 +00:00
parent a61d1d1a03
commit 3278f6358c
3 changed files with 42 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import androidx.preference.PreferenceManager
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import oppen.ariane.io.GemState
import oppen.ariane.io.keymanager.ArianeKeyManager
import oppen.isGemini
import oppen.toURI
import oppen.toUri
@ -23,6 +24,7 @@ class GeminiDatasource(private val context: Context): Datasource {
private val addressBuilder = AddressBuilder()
private val runtimeHistory = mutableListOf<URI>()
private var forceDownload = false
private val arianeKeyManager = ArianeKeyManager()
override fun request(uri: URI, onUpdate: (state: GemState) -> Unit) = request(uri, false, onUpdate)
@ -72,29 +74,25 @@ class GeminiDatasource(private val context: Context): Datasource {
}
}
/**
*
* This was originally largely copied from:
https://framagit.org/waweic/gemini-client/-/blob/master/app/src/main/java/rocks/ism/decentral/geminiclient/GeminiConnection.kt
*
*/
private fun geminiRequest(uri: URI, onUpdate: (state: GemState) -> Unit){
val port = if(uri.port == -1) 1965 else uri.port
//todo - extract and reuse this ------------------------------------------------------------
val protocol = prefs.getString("tls_protocol", "TLS")
println("REQ_PROTOCOL: $protocol")
//todo - extract and reuse this
val sslContext = when (protocol) {
"TLS_ALL" -> SSLContext.getInstance("TLS")
else -> SSLContext.getInstance(protocol)
}
sslContext.init(null, DummyTrustManager.get(), null)
sslContext.init(arianeKeyManager.getFactory()?.keyManagers, DummyTrustManager.get(), null)
val factory: SSLSocketFactory = sslContext.socketFactory
//todo to here ----------------------------------------------------------------------------
val socket: SSLSocket?
try {
socket = factory.createSocket(uri.host, port) as SSLSocket
@ -104,6 +102,7 @@ class GeminiDatasource(private val context: Context): Datasource {
"TLS_ALL" -> socket.enabledProtocols = socket.supportedProtocols
else -> socket.enabledProtocols = arrayOf(protocol)
}
println("Ariane socket handshake with ${uri.host} on port $port")
socket.startHandshake()
}catch (ce: ConnectException){
@ -116,7 +115,6 @@ class GeminiDatasource(private val context: Context): Datasource {
return
}
// OUT >>>>>>>>>>>>>>>>>>>>>>>>>>
val outputStreamWriter = OutputStreamWriter(socket.outputStream)
val bufferedWriter = BufferedWriter(outputStreamWriter)

View File

@ -0,0 +1,33 @@
package oppen.ariane.io.keymanager
import android.R
import android.content.Context
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.security.KeyStore
import javax.net.ssl.KeyManagerFactory
class ArianeKeyManager {
//todo - add other methods to update state
//If the user has a key loaded load it here - or else return null
fun getFactory(): KeyManagerFactory? {
val hasLoadedKey = false
return when {
hasLoadedKey -> {
val keyStore: KeyStore = KeyStore.getInstance("BKS")
val inputStream: InputStream = ByteArrayInputStream("dummy".toByteArray())
keyStore.load(inputStream, "yourKeyStorePassword".toCharArray())
inputStream.close()
val keyManagerFactory: KeyManagerFactory = KeyManagerFactory.getInstance("X509")
keyManagerFactory.init(keyStore, "yourKeyStorePassword".toCharArray())
keyManagerFactory
}
else -> null
}
}
}

View File

@ -150,6 +150,7 @@
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay"
android:paddingTop="@dimen/screen_margin"
android:paddingBottom="@dimen/screen_margin"
/>