Skip to content

Commit

Permalink
Merge pull request #229 from xyoye/dev_4.2.0
Browse files Browse the repository at this point in the history
代码完善: 修改远程媒体库地址为自定义
  • Loading branch information
xyoye authored Mar 3, 2024
2 parents 6f1f93b + 2d9a450 commit 4972c07
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RemoteStorage(library: MediaLibraryEntity) : AbstractStorage(library) {

private var storageFilesSnapshot = listOf<RemoteVideoData>()

override var rootUri: Uri = Uri.parse("http://${library.url}:${library.port}")
override var rootUri: Uri = generateRootUri()

override suspend fun listFiles(file: StorageFile): List<StorageFile> {
return if (file.isRootFile()) {
Expand Down Expand Up @@ -133,4 +133,14 @@ class RemoteStorage(library: MediaLibraryEntity) : AbstractStorage(library) {
}
}
}

private fun generateRootUri(): Uri {
// 兼容旧模式数据
val noScheme = Uri.parse(library.url).scheme.isNullOrEmpty()
if (noScheme) {
return Uri.parse("http://${library.url}:${library.port}")
}

return Uri.parse(library.url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AlistStorageEditDialog(

private fun checkParams(serverData: MediaLibraryEntity): Boolean {
if (serverData.url.isEmpty()) {
ToastCenter.showWarning("请填写服务器名称或IP地址")
ToastCenter.showWarning("请填写服务器地址")
return false
}
if (!serverData.url.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class RemoteStorageEditDialog(
if (remoteData.displayName.isEmpty()) {
remoteData.displayName = "远程媒体库"
}
remoteData.describe = "http://${remoteData.url}:${remoteData.port}"
remoteData.describe = remoteData.url
activity.addStorage(remoteData)
}
}
Expand All @@ -102,7 +102,17 @@ class RemoteStorageEditDialog(

private fun checkParams(remoteData: MediaLibraryEntity): Boolean {
if (remoteData.url.isEmpty()) {
ToastCenter.showWarning("请填写IP地址")
ToastCenter.showWarning("请填写服务器地址")
return false
}

if (!remoteData.url.endsWith("/")) {
remoteData.url = "${remoteData.url}/"
}

val serverUrl = remoteData.url
if (!serverUrl.startsWith("http://") && !serverUrl.startsWith("https://")) {
ToastCenter.showWarning("请填写服务器协议:http或https")
return false
}

Expand All @@ -129,8 +139,7 @@ class RemoteStorageEditDialog(
if (data == null) {
return@block
}
remoteData.url = data.selectedIP ?: ""
remoteData.port = data.port
remoteData.url = "http://${data.selectedIP.orEmpty()}:${data.port}/"
remoteData.displayName = data.machineName ?: ""
tokenRequired = data.tokenRequired
binding.remoteData = remoteData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class WebDavStorageEditDialog(

private fun checkParams(serverData: MediaLibraryEntity): Boolean {
if (serverData.url.isEmpty()) {
ToastCenter.showWarning("请填写服务器名称或IP地址")
ToastCenter.showWarning("请填写服务器地址")
return false
}
if (!serverData.url.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:layout_height="48dp"
android:background="@drawable/background_dialog_edit"
android:gravity="center_vertical"
android:hint="@string/hint_web_dav_address"
android:hint="@string/hint_server_address"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
Expand Down
55 changes: 14 additions & 41 deletions storage_component/src/main/res/layout/dialog_remote_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,21 @@
android:layout_gravity="center_vertical"
android:orientation="vertical">

<LinearLayout
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/address_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/address_et"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginEnd="5dp"
android:layout_weight="1"
android:background="@drawable/background_dialog_edit"
android:gravity="center_vertical"
android:hint="@string/hint_web_dav_address"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:text="@={remoteData.url}"
android:textColor="@color/text_black"
android:textColorHint="@color/text_gray"
android:textSize="14sp" />

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/port_et"
android:layout_width="100dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:background="@drawable/background_dialog_edit"
android:gravity="center"
android:hint="@string/hint_port"
android:inputType="number"
android:maxLength="5"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:text="@={BindingConverter.intToString(remoteData.port)}"
android:textColor="@color/text_black"
android:textColorHint="@color/text_gray"
android:textSize="14sp" />
</LinearLayout>
android:layout_height="48dp"
android:background="@drawable/background_dialog_edit"
android:gravity="center_vertical"
android:hint="@string/hint_server_address"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:text="@={remoteData.url}"
android:textColor="@color/text_black"
android:textColorHint="@color/text_gray"
android:textSize="14sp" />

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/display_name_et"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:layout_height="48dp"
android:background="@drawable/background_dialog_edit"
android:gravity="center_vertical"
android:hint="@string/hint_web_dav_address"
android:hint="@string/hint_server_address"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
Expand Down
2 changes: 1 addition & 1 deletion storage_component/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<string name="storage_file_scroll_behavior">com.xyoye.storage_component.ui.weight.StorageFileBehavior</string>

<string name="app_name">storage_component</string>
<string name="hint_web_dav_address">服务器名称或IP地址</string>
<string name="hint_server_address">服务器地址,如:http://127.0.0.1:80/</string>
<string name="hint_display_name">显示名称(可空)</string>
<string name="tips_login_mode">登录模式</string>
<string name="text_account_login">帐号登录</string>
Expand Down

0 comments on commit 4972c07

Please sign in to comment.