From 94fdb645577137c76bf7887169b611a61d30223f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 30 Aug 2019 14:48:53 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 4 ++-- .../java/io/legado/app/lib/webdav/http/HttpAuth.kt | 5 ----- .../main/java/io/legado/app/lib/webdav/http/OkHttp.kt | 10 +++------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 4ca1966c8..f35e41db3 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -32,7 +32,7 @@ constructor(url: String) { return field } - private val okHttpClient: OkHttpClient = OkHttp.SingletonHelper.okHttpClient + private val okHttpClient: OkHttpClient = OkHttp.okHttpClient val path: String get() = url.toString() @@ -207,7 +207,7 @@ constructor(url: String) { fun upload(localPath: String, contentType: String? = null): Boolean { val file = File(localPath) if (!file.exists()) return false - val mediaType = if (contentType == null) null else contentType.toMediaTypeOrNull() + val mediaType = contentType?.toMediaTypeOrNull() // 务必注意RequestBody不要嵌套,不然上传时内容可能会被追加多余的文件信息 val fileBody = RequestBody.create(mediaType, file) getUrl()?.let { diff --git a/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt b/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt index 3a6f31b48..07cab5855 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/http/HttpAuth.kt @@ -3,11 +3,6 @@ package io.legado.app.lib.webdav.http object HttpAuth { var auth: Auth? = null - private set - - fun setAuth(user: String, password: String) { - auth = Auth(user, password) - } class Auth internal constructor(val user: String, val pass: String) diff --git a/app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt b/app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt index f088fc785..6861deb62 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/http/OkHttp.kt @@ -2,10 +2,6 @@ package io.legado.app.lib.webdav.http import okhttp3.OkHttpClient -class OkHttp private constructor() { - - object SingletonHelper { - val okHttpClient: OkHttpClient = OkHttpClient.Builder().build() - } - -} +object OkHttp { + val okHttpClient: OkHttpClient = OkHttpClient.Builder().build() +} \ No newline at end of file