Skip to content

Commit

Permalink
Feat: Add WebDAV UI
Browse files Browse the repository at this point in the history
Bug: #191
  • Loading branch information
zhanghai committed Feb 27, 2024
1 parent b9e8471 commit 84187fc
Show file tree
Hide file tree
Showing 15 changed files with 864 additions and 9 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@
android:label="@string/storage_edit_smb_server_title_edit"
android:theme="@style/Theme.MaterialFiles" />

<activity
android:name="me.zhanghai.android.files.storage.EditWebDavServerActivity"
android:label="@string/storage_edit_webdav_server_title_edit"
android:theme="@style/Theme.MaterialFiles" />

<activity
android:name="me.zhanghai.android.files.navigation.EditBookmarkDirectoryDialogActivity"
android:label="@string/navigation_edit_bookmark_directory_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import me.zhanghai.android.files.storage.FtpServerAuthenticator
import me.zhanghai.android.files.storage.SftpServerAuthenticator
import me.zhanghai.android.files.storage.SmbServerAuthenticator
import me.zhanghai.android.files.storage.StorageVolumeListLiveData
import me.zhanghai.android.files.storage.WebDavServerAuthenticator
import me.zhanghai.android.files.theme.custom.CustomThemeHelper
import me.zhanghai.android.files.theme.night.NightModeHelper
import java.util.Properties
import me.zhanghai.android.files.provider.ftp.client.Client as FtpClient
import me.zhanghai.android.files.provider.sftp.client.Client as SftpClient
import me.zhanghai.android.files.provider.smb.client.Client as SmbClient
import me.zhanghai.android.files.provider.webdav.client.Client as WebDavClient

val appInitializers = listOf(
::initializeCrashlytics, ::disableHiddenApiChecks, ::initializeThreeTen,
Expand Down Expand Up @@ -75,6 +77,7 @@ private fun initializeFileSystemProviders() {
FtpClient.authenticator = FtpServerAuthenticator
SftpClient.authenticator = SftpServerAuthenticator
SmbClient.authenticator = SmbServerAuthenticator
WebDavClient.authenticator = WebDavServerAuthenticator
}

private fun initializeLiveDataObjects() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ object WebDavFileSystemProvider : FileSystemProvider(), PathObservableProvider,
get() {
val protocol = Protocol.fromScheme(scheme)
val port = if (port != -1) port else protocol.defaultPort
return Authority(protocol, host, port, userInfo)
val username = userInfo.orEmpty()
return Authority(protocol, host, port, username)
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class PasswordAuthentication(
override fun createAuthenticatorInterceptor(authority: Authority): AuthenticatorInterceptor =
object : AuthenticatorInterceptor {
private val basicDigestAuthHandler = BasicDigestAuthHandler(
UrlUtils.hostToDomain(authority.host), authority.username!!, password
UrlUtils.hostToDomain(authority.host), authority.username, password
)

override fun authenticate(route: Route?, response: Response): Request? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ package me.zhanghai.android.files.provider.webdav.client
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import me.zhanghai.android.files.provider.common.UriAuthority
import me.zhanghai.android.files.util.takeIfNotEmpty

@Parcelize
data class Authority(
val protocol: Protocol,
val host: String,
val port: Int,
val username: String?
val username: String
) : Parcelable {
init {
require(username == null || username.isNotEmpty()) { "Username cannot be empty" }
}

fun toUriAuthority(): UriAuthority {
val userInfo = username.takeIfNotEmpty()
val uriPort = port.takeIf { it != protocol.defaultPort }
return UriAuthority(username, host, uriPort)
return UriAuthority(userInfo, host, uriPort)
}

override fun toString(): String = toUriAuthority().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ class AddStorageDialogFragment : AppCompatDialogFragment() {
EditFtpServerActivity::class.createIntent().putArgs(EditFtpServerFragment.Args()),
R.string.storage_add_storage_sftp_server to
EditSftpServerActivity::class.createIntent().putArgs(EditSftpServerFragment.Args()),
R.string.storage_add_storage_smb_server to AddLanSmbServerActivity::class.createIntent()
R.string.storage_add_storage_smb_server to
AddLanSmbServerActivity::class.createIntent(),
R.string.storage_add_storage_webdav_server to
EditWebDavServerActivity::class.createIntent()
.putArgs(EditWebDavServerFragment.Args()),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Hai Zhang <dreaming.in.code.zh@gmail.com>
* All Rights Reserved.
*/

package me.zhanghai.android.files.storage

import android.os.Bundle
import android.view.View
import androidx.fragment.app.commit
import me.zhanghai.android.files.app.AppActivity
import me.zhanghai.android.files.util.args
import me.zhanghai.android.files.util.putArgs

class EditWebDavServerActivity : AppActivity() {
private val args by args<EditWebDavServerFragment.Args>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Calls ensureSubDecor().
findViewById<View>(android.R.id.content)
if (savedInstanceState == null) {
val fragment = EditWebDavServerFragment().putArgs(args)
supportFragmentManager.commit { add(android.R.id.content, fragment) }
}
}
}
Loading

0 comments on commit 84187fc

Please sign in to comment.