Merge pull request #2076 from 821938089/compatible-custom-webdav

优化自建webdav
pull/2077/head
kunfei 2 years ago committed by GitHub
commit fbc001df9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt
  4. 2
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -70,10 +70,13 @@ open class WebDav(val path: String, val authorization: Authorization) {
} }
private val webDavClient by lazy { private val webDavClient by lazy {
val authInterceptor = Interceptor { chain -> val authInterceptor = Interceptor { chain ->
val request = chain.request() var request = chain.request()
if (request.url.host == host) {
request = request
.newBuilder() .newBuilder()
.header(authorization.name, authorization.data) .header(authorization.name, authorization.data)
.build() .build()
}
chain.proceed(request) chain.proceed(request)
} }
okHttpClient.newBuilder().run { okHttpClient.newBuilder().run {

@ -151,7 +151,7 @@ class RemoteBookActivity : VMBaseActivity<ActivityImportBookBinding, RemoteBookV
viewModel.dataCallback?.clear() viewModel.dataCallback?.clear()
adapter.selected.clear() adapter.selected.clear()
viewModel.loadRemoteBookList( viewModel.loadRemoteBookList(
viewModel.dirList.lastOrNull()?.path ?: RemoteBookWebDav.rootBookUrl viewModel.dirList.lastOrNull()?.path
) { ) {
if (it) { if (it) {
waitDialog.show() waitDialog.show()

@ -74,9 +74,10 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun loadRemoteBookList(path: String, loadCallback: (loading: Boolean) -> Unit) { fun loadRemoteBookList(path: String?, loadCallback: (loading: Boolean) -> Unit) {
execute { execute {
dataCallback?.clear() dataCallback?.clear()
val path = path ?: RemoteBookWebDav.rootBookUrl
val bookList = RemoteBookWebDav.getRemoteBookList(path) val bookList = RemoteBookWebDav.getRemoteBookList(path)
dataCallback?.setItems(bookList) dataCallback?.setItems(bookList)
}.onError { }.onError {

@ -286,7 +286,7 @@ class BackupConfigFragment : PreferenceFragment(),
} }
fun restore() { fun restore() {
Coroutine.async(context = Main) { Coroutine.async {
AppWebDav.showRestoreDialog(requireContext()) AppWebDav.showRestoreDialog(requireContext())
}.onError { }.onError {
alert { alert {

Loading…
Cancel
Save