Parcourir la source

播放跳转到首页 播放状态bug的修复

onecold il y a 9 mois
Parent
commit
227906d1e7

+ 2 - 2
entry/src/main/ets/common/util/Utility.ets

@@ -1648,7 +1648,7 @@ function formatDuration(seconds: string, forceHHMMSS: boolean = false): string {
 /**
  * 定义解析结果的数据结构
  */
-class MusicInfo {
+export class MusicInfo {
   artist: string = "";  // 艺术家名称
   title: string = "";   // 歌曲名称
   isValid: boolean = false;  // 格式是否有效
@@ -1691,7 +1691,7 @@ const ARTIST_KEYWORDS = [
 /**
  * 智能解析音乐文件名
  */
-function parseMusicFileName(fileName: string): MusicInfo {
+export function parseMusicFileName(fileName: string): MusicInfo {
   const result: MusicInfo = new MusicInfo();
   if (!fileName) return result;
 

+ 10 - 1
entry/src/main/ets/common/util/WebdavManager.ets

@@ -14,6 +14,7 @@ import Logger from './Logger';
 import { buffer } from '@kit.ArkTS';
 import { CommonConstants } from '../constants/CommonConstants';
 import { GlobalContext } from '@pura/harmony-utils';
+import { MusicInfo, parseMusicFileName, Utility } from './Utility';
 
 const TAG = 'heanup WebdavManager';
 
@@ -507,13 +508,14 @@ export class WebdavManager {
 
     // 创建VideoItem对象
     // 构造函数签名: (name, id, filePath, type, videoSize, cTime, pixelMap?, size?, pixelMapPath?, artist?, album?, fileName?, lastPlayed?)
+
     const videoItem = new VideoItem(
       this.getFileNameWithoutExtension(fileInfo.fileName), // name: 歌曲名
       '', // id: 空字符串,WebDAV文件无本地ID
       filePath, // filePath: 文件路径
       CommonConstants.TYPE_WEBDAV, // type: WebDAV类型
       fileInfo.contentLength, // videoSize: 文件大小
-      fileInfo.time.toString(), // cTime: 修改时间
+      Utility.getFormatDateStr(fileInfo.time,'yyyy-MM-dd HH:mm'), // cTime: 修改时间
       undefined, // pixelMap
       undefined, // size
       undefined, // pixelMapPath: 对于WebDAV歌曲不设置图片路径
@@ -521,6 +523,13 @@ export class WebdavManager {
       undefined, // album: 专辑
       fileInfo.fileName // fileName: 真实文件名
     );
+    videoItem.size = Utility.formatFSize(fileInfo.contentLength)
+    //根据文件名解析艺术家
+    const musicData:MusicInfo = parseMusicFileName(fileInfo.fileName);
+    if (musicData.isValid)  {
+      console.log('onecold parseMusicFileName  artist:', musicData.artist)
+      videoItem.artist = musicData.artist
+    }
 
     return videoItem;
   }

+ 48 - 32
entry/src/main/ets/dialog/PlaylistDialog.ets

@@ -60,6 +60,17 @@ struct PlaylistDialogContent {
   }
 
   build() {
+    Scroll(){
+      this.contentBuilder()
+    }
+    .width('100%')
+    .scrollBar(BarState.Off)
+
+
+  }
+
+  @Builder
+  contentBuilder() {
     Column({ space: 20 }) {
       // 标题
       // Text(this.isEditMode ? '编辑歌单' : '创建歌单')
@@ -68,14 +79,13 @@ struct PlaylistDialogContent {
       //   .fontColor($r('app.color.text_color'))
       //   .visibility(this.isEditMode?Visibility.None:Visibility.Visible)
       //   .margin({ top: 20 })
-
       // 歌单封面选择
       Column({ space: 8 }) {
         Text('歌单封面(可选)')
           .fontSize(14)
           .fontColor(this.isDarkMode ? '#EBEBF5' : '#666666')
           .fontWeight(FontWeight.Medium)
-          .alignSelf(ItemAlign.Start)
+          .alignSelf(ItemAlign.Start);
 
         // 封面选择区域
         Row({ space: 12 }) {
@@ -86,25 +96,25 @@ struct PlaylistDialogContent {
                 .width(80)
                 .height(80)
                 .borderRadius(8)
-                .objectFit(ImageFit.Cover)
+                .objectFit(ImageFit.Cover);
             } else {
               // 默认封面图标
               Column() {
                 Image($r('app.media.hm_music'))
                   .width(40)
                   .height(40)
-                  .fillColor(this.isDarkMode ? Color.White : this.themeColor)
+                  .fillColor(this.isDarkMode ? Color.White : this.themeColor);
               }
               .width(80)
               .height(80)
               .backgroundColor(this.isDarkMode ? '#2C2C2E' : $r('app.color.input_background'))
               .borderRadius(8)
-              .justifyContent(FlexAlign.Center)
+              .justifyContent(FlexAlign.Center);
             }
           }
           .onClick(() => {
-            this.handleSelectCover()
-          })
+            this.handleSelectCover();
+          });
 
           // 操作按钮
           Column({ space: 8 }) {
@@ -115,8 +125,8 @@ struct PlaylistDialogContent {
               .fontColor(this.isDarkMode ? '#FFFFFF' : $r('app.color.text_color'))
               .backgroundColor(this.isDarkMode ? '#2C2C2E' : $r('app.color.input_background'))
               .onClick(() => {
-                this.handleSelectCover()
-              })
+                this.handleSelectCover();
+              });
 
             if (this.coverPath) {
               Button('移除封面')
@@ -126,17 +136,17 @@ struct PlaylistDialogContent {
                 .fontColor(this.isDarkMode ? '#FF453A' : Color.Red)
                 .backgroundColor(this.isDarkMode ? 'rgba(255,69,58,0.2)' : '#FFE5E5')
                 .onClick(() => {
-                  this.handleRemoveCover()
-                })
+                  this.handleRemoveCover();
+                });
             }
           }
-          .alignItems(HorizontalAlign.Start)
+          .alignItems(HorizontalAlign.Start);
         }
         .width('100%')
-        .justifyContent(FlexAlign.Start)
+        .justifyContent(FlexAlign.Start);
       }
       .width('100%')
-      .alignItems(HorizontalAlign.Start)
+      .alignItems(HorizontalAlign.Start);
 
       // 歌单名称输入框
       Column({ space: 8 }) {
@@ -144,7 +154,7 @@ struct PlaylistDialogContent {
           .fontSize(14)
           .fontColor(this.isDarkMode ? '#EBEBF5' : '#666666')
           .fontWeight(FontWeight.Medium)
-          .alignSelf(ItemAlign.Start)
+          .alignSelf(ItemAlign.Start);
 
         TextInput({ placeholder: '请输入歌单名称', text: this.playlistName })
           .width('100%')
@@ -156,11 +166,11 @@ struct PlaylistDialogContent {
           .fontColor(this.isDarkMode ? '#FFFFFF' : $r('app.color.text_color'))
           .placeholderColor(this.isDarkMode ? '#8E8E93' : '#999999')
           .onChange((value: string) => {
-            this.playlistName = value
-          })
+            this.playlistName = value;
+          });
       }
       .width('100%')
-      .alignItems(HorizontalAlign.Start)
+      .alignItems(HorizontalAlign.Start);
 
       // 歌单描述输入框
       Column({ space: 8 }) {
@@ -168,27 +178,32 @@ struct PlaylistDialogContent {
           .fontSize(14)
           .fontColor(this.isDarkMode ? '#EBEBF5' : '#666666')
           .fontWeight(FontWeight.Medium)
-          .alignSelf(ItemAlign.Start)
+          .alignSelf(ItemAlign.Start);
 
         TextArea({ placeholder: '请输入歌单描述', text: this.playlistDescription })
           .width('100%')
           .height(80)
           // .backgroundColor(this.isDarkMode ? '#2C2C2E' : $r('app.color.input_background'))
           .borderRadius(8)
-          .padding({ left: 12, right: 12, top: 8, bottom: 8 })
+          .padding({
+            left: 12,
+            right: 12,
+            top: 8,
+            bottom: 8
+          })
           .fontSize(14)
           .fontColor(this.isDarkMode ? '#FFFFFF' : $r('app.color.text_color'))
           .placeholderColor(this.isDarkMode ? '#8E8E93' : '#999999')
           .onChange((value: string) => {
-            this.playlistDescription = value
-          })
+            this.playlistDescription = value;
+          });
       }
       .width('100%')
-      .alignItems(HorizontalAlign.Start)
+      .alignItems(HorizontalAlign.Start);
 
       // 按钮区域
       Row({ space: 12 }) {
-        Button('取消',{ type: ButtonType.Capsule, stateEffect: true })
+        Button('取消', { type: ButtonType.Capsule, stateEffect: true })
           .width('45%')
           .height(40)
           .backgroundColor($r('app.color.cancel_button_background'))
@@ -196,25 +211,26 @@ struct PlaylistDialogContent {
           .fontSize(14)
           .fontColor($r('app.color.cancel_button_text'))
           .onClick(() => {
-            this.onCancel?.()
+            this.onCancel?.();
             // 关闭对话框
-            DialogHelper.closeDialog(this.isEditMode ? 'editPlaylistDialog' : 'createPlaylistDialog')
-          })
+            DialogHelper.closeDialog(this.isEditMode ? 'editPlaylistDialog' : 'createPlaylistDialog');
+          });
 
-        Button(this.isEditMode ? '保存' : '创建',{ type: ButtonType.Capsule, stateEffect: true })
+        Button(this.isEditMode ? '保存' : '创建', { type: ButtonType.Capsule, stateEffect: true })
           .width('45%')
           .height(40)
-          .backgroundColor(this.isDarkMode ? themeColorWithAlpha(this.themeColor, 0.8, this.isDarkMode) : this.themeColor)
+          .backgroundColor(this.isDarkMode ? themeColorWithAlpha(this.themeColor, 0.8, this.isDarkMode) :
+            this.themeColor)
           .borderRadius(8)
           .fontSize(14)
           .fontColor(Color.White)
           .onClick(() => {
-            this.handleConfirm()
-          })
+            this.handleConfirm();
+          });
       }
       .width('100%')
       .justifyContent(FlexAlign.SpaceBetween)
-      .margin({ top: 20, bottom: 20 })
+      .margin({ top: 20, bottom: 20 });
     }
     .width('100%')
     // .backgroundColor(this.isDarkMode ? '#1C1C1E' : $r('app.color.dialog_background'))

+ 51 - 40
entry/src/main/ets/dialog/WebDavAccountDialog.ets

@@ -63,12 +63,23 @@ export struct WebDavAccountDialog {
   }
 
   build() {
+    Scroll(){
+      this.contentBuilder()
+    }
+    .height('100%')
+    .width('100%')
+    .scrollBar(BarState.Off)
+
+  }
+
+  @Builder
+  contentBuilder() {
     Column({ space: 16 }) {
       // 标题
       Text(this.isEditMode ? '编辑账户' : '添加账户')
         .fontSize(18)
         .fontWeight(FontWeight.Bold)
-        .fontColor($r('app.color.index_tab_font_color'))
+        .fontColor($r('app.color.index_tab_font_color'));
 
       // 账户封面选择
       Column({ space: 8 }) {
@@ -76,7 +87,7 @@ export struct WebDavAccountDialog {
           .fontSize(14)
           .fontColor(this.isDarkMode ? '#EBEBF5' : '#666666')
           .fontWeight(FontWeight.Medium)
-          .alignSelf(ItemAlign.Start)
+          .alignSelf(ItemAlign.Start);
 
         // 封面选择区域
         Row({ space: 12 }) {
@@ -87,25 +98,25 @@ export struct WebDavAccountDialog {
                 .width(80)
                 .height(80)
                 .borderRadius(8)
-                .objectFit(ImageFit.Cover)
+                .objectFit(ImageFit.Cover);
             } else {
               // 默认封面图标
               Column() {
                 Image($r('app.media.cloudDisk'))
                   .width(40)
                   .height(40)
-                  .fillColor(this.isDarkMode ? Color.White : this.themeColor)
+                  .fillColor(this.isDarkMode ? Color.White : this.themeColor);
               }
               .width(80)
               .height(80)
               .backgroundColor(this.isDarkMode ? '#2C2C2E' : $r('app.color.input_background'))
               .borderRadius(8)
-              .justifyContent(FlexAlign.Center)
+              .justifyContent(FlexAlign.Center);
             }
           }
           .onClick(() => {
-            this.handleSelectCover()
-          })
+            this.handleSelectCover();
+          });
 
           // 操作按钮
           Column({ space: 8 }) {
@@ -116,8 +127,8 @@ export struct WebDavAccountDialog {
               .fontColor(this.isDarkMode ? '#FFFFFF' : $r('app.color.text_color'))
               .backgroundColor(this.isDarkMode ? '#2C2C2E' : $r('app.color.input_background'))
               .onClick(() => {
-                this.handleSelectCover()
-              })
+                this.handleSelectCover();
+              });
 
             if (this.coverPath) {
               Button('移除封面')
@@ -127,118 +138,118 @@ export struct WebDavAccountDialog {
                 .fontColor(this.isDarkMode ? '#FF453A' : Color.Red)
                 .backgroundColor(this.isDarkMode ? 'rgba(255,69,58,0.2)' : '#FFE5E5')
                 .onClick(() => {
-                  this.handleRemoveCover()
-                })
+                  this.handleRemoveCover();
+                });
             }
           }
-          .alignItems(HorizontalAlign.Start)
+          .alignItems(HorizontalAlign.Start);
         }
         .width('100%')
-        .justifyContent(FlexAlign.Start)
+        .justifyContent(FlexAlign.Start);
       }
       .width('100%')
-      .alignItems(HorizontalAlign.Start)
+      .alignItems(HorizontalAlign.Start);
 
       // 账户名称
       Row({ space: 8 }) {
         Text('名称')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextArea({ placeholder: '请输入账户名称', text: this.accountName })
           .layoutWeight(1)
           .maxLines(1)
           .onChange((value: string) => {
             this.accountName = value;
-          })
+          });
       }
       .width('100%')
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // 服务器地址
       Row({ space: 8 }) {
         Text('服务器')
           .fontSize(14)
           .maxLines(2)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextArea({ placeholder: '例如: example.com', text: this.host })
           .layoutWeight(1)
           .onChange((value: string) => {
             this.host = value;
-          })
+          });
       }
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // 端口
       Row({ space: 8 }) {
         Text('端口')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextInput({ placeholder: '默认: 80', text: this.port.toString() })
           .layoutWeight(1)
           .maxLines(1)
           .type(InputType.Number)
           .onChange((value: string) => {
             this.port = parseInt(value) || 80;
-          })
+          });
       }
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // 文件目录
       Row({ space: 8 }) {
         Text('文件目录')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextInput({ placeholder: '例如: /music', text: this.filepath })
           .layoutWeight(1)
           .maxLines(1)
           .onChange((value: string) => {
             this.filepath = value;
-          })
+          });
       }
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // 用户名
       Row({ space: 8 }) {
         Text('用户名')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextInput({ placeholder: '请输入用户名', text: this.username })
           .layoutWeight(1)
           .maxLines(1)
           .onChange((value: string) => {
             this.username = value;
-          })
+          });
       }
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // 密码
       Row({ space: 8 }) {
         Text('密码')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
+          .fontColor($r('app.color.index_tab_font_color'));
         TextInput({ placeholder: '请输入密码', text: this.password })
           .type(InputType.Password)
           .layoutWeight(1)
           .maxLines(2)
           .onChange((value: string) => {
             this.password = value;
-          })
+          });
       }
-      .alignItems(VerticalAlign.Center)
+      .alignItems(VerticalAlign.Center);
 
       // HTTPS开关
       Row() {
         Text('启用HTTPS')
           .fontSize(14)
-          .fontColor($r('app.color.index_tab_font_color'))
-        Blank()
+          .fontColor($r('app.color.index_tab_font_color'));
+        Blank();
         Toggle({ type: ToggleType.Switch, isOn: this.enableHttps })
           .selectedColor(this.themeColor)
           .onChange((isOn: boolean) => {
             this.enableHttps = isOn;
-          })
+          });
       }
-      .width('100%')
+      .width('100%');
 
       // 按钮
       Row({ space: 12 }) {
@@ -248,7 +259,7 @@ export struct WebDavAccountDialog {
           .layoutWeight(1)
           .onClick(() => {
             this.onCancel?.();
-          })
+          });
 
         Button(this.isEditMode ? '保存' : '添加', { type: ButtonType.Capsule })
           .backgroundColor(this.themeColor)
@@ -260,7 +271,7 @@ export struct WebDavAccountDialog {
             }
 
             const updatedAccount = new WebDavAccount();
-            if(this.isEditMode){
+            if (this.isEditMode) {
               updatedAccount.id = this.account.id;
             }
             updatedAccount.name = this.accountName;
@@ -279,10 +290,10 @@ export struct WebDavAccountDialog {
             updatedAccount.imageFilePath = '';
             this.onConfirm?.(updatedAccount);
 
-          })
+          });
       }
       .width('100%')
-      .margin({ top: 8 })
+      .margin({ top: 8 });
     }
     .padding(24)
     .width('90%')

+ 17 - 6
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -678,12 +678,23 @@ export struct WebDavMainPage {
             .maxLines(1)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
 
-          Text(decodeUrlEncodedString(song.artist||""))
-            .fontSize(13)
-            .fontColor($r('app.color.index_tab_font_color'))
-            .opacity(0.6)
-            .maxLines(1)
-            .textOverflow({ overflow: TextOverflow.Ellipsis })
+          Row(){
+            Text(song.artist)
+              .fontSize(13)
+              .fontColor($r('app.color.index_tab_font_color'))
+              .opacity(0.6)
+              .maxLines(1)
+              .visibility(song.artist?Visibility.Visible:Visibility.None)
+              .textOverflow({ overflow: TextOverflow.Ellipsis })
+            Text(decodeUrlEncodedString(song.size||"")+'  '+song.cTime)
+              .fontSize(13)
+              .fontColor($r('app.color.index_tab_font_color'))
+              .opacity(0.6)
+              .maxLines(1)
+              .textOverflow({ overflow: TextOverflow.Ellipsis })
+          }
+
+
         }
         .alignItems(HorizontalAlign.Start)
         .layoutWeight(1)