Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 676f74a5 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

HttpClient: close cache, provide app:html binding

parent 22b9624c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka-android'

android {
@@ -83,7 +84,7 @@ dependencies {

    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.fragment:fragment:1.0.0'
    implementation 'androidx.fragment:fragment-ktx:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
+8 −2
Original line number Diff line number Diff line
@@ -47,8 +47,11 @@ class HttpClient private constructor(
): AutoCloseable {

    companion object {
        /** max. size of disk cache (10 MB) */
        const val DISK_CACHE_MAX_SIZE: Long = 10*1024*1024

        /** [OkHttpClient] singleton to build all clients from */
        val sharedClient = OkHttpClient.Builder()
        val sharedClient: OkHttpClient = OkHttpClient.Builder()
                // set timeouts
                .connectTimeout(15, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
@@ -63,7 +66,9 @@ class HttpClient private constructor(
                .build()
    }


    override fun close() {
        okHttpClient.cache()?.close()
        certManager?.close()
    }

@@ -74,6 +79,7 @@ class HttpClient private constructor(
    ) {
        private var certManager: CustomCertManager? = null
        private var certificateAlias: String? = null
        private var cache: Cache? = null

        private val orig = sharedClient.newBuilder()

@@ -134,7 +140,7 @@ class HttpClient private constructor(
                    val cacheDir = File(dir, "HttpClient")
                    cacheDir.mkdir()
                    Logger.log.fine("Using disk cache: $cacheDir")
                    orig.cache(Cache(cacheDir, 10*1024*1024))
                    orig.cache(Cache(cacheDir, DISK_CACHE_MAX_SIZE))
                    break
                }
            }
+16 −2
Original line number Diff line number Diff line
package at.bitfire.davdroid.ui.widget

import android.text.method.LinkMovementMethod
import android.widget.TextView
import androidx.core.text.HtmlCompat
import androidx.databinding.BindingAdapter

object BindingAdapters {

    @BindingAdapter("error")
    fun setError(textView: TextView, text: String) {
        textView.error = text
    @JvmStatic
    fun setError(textView: TextView, error: String?) {
        textView.error = error
        textView.requestFocus()
    }

    @BindingAdapter("html")
    @JvmStatic
    fun setHtml(textView: TextView, html: String?) {
        if (html != null) {
            textView.text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
            textView.movementMethod = LinkMovementMethod.getInstance()
        } else
            textView.text = null
    }

}
 No newline at end of file