Jelajahi Sumber

网盘的长按 歌曲有属性窗口功能

onecold 5 bulan lalu
induk
melakukan
b5eff0ea99
1 mengubah file dengan 119 tambahan dan 0 penghapusan
  1. 119 0
      entry/src/main/ets/pages/WebDavMainPage.ets

+ 119 - 0
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -140,6 +140,8 @@ export struct WebDavMainPage {
   @State isAllSelected: boolean = false
   @State isDeletingSelection: boolean = false
   @State ignoreTapAfterExitMultiSelect: boolean = false
+  @State isShowSongPropertySheet: boolean = false
+  @State songForPropertySheet: VideoItem | undefined = undefined
   @State rootPath: string = ''
   @State isShowDownloadCenter: boolean = false
   @State downloadCenterTabIndex: number[] = [0]
@@ -2358,6 +2360,107 @@ export struct WebDavMainPage {
     this.updateListData(this.filteredList);
   }
 
+  private openSongPropertySheet(song: VideoItem): void {
+    this.songForPropertySheet = song;
+    this.isShowSongPropertySheet = true;
+  }
+
+  private getSongPropertyValue(value: string | number | undefined): string {
+    if (value === undefined) {
+      return '--';
+    }
+    if (typeof value === 'number') {
+      return `${value}`;
+    }
+    if (StrUtil.isEmpty(value)) {
+      return '--';
+    }
+    return value;
+  }
+
+  private getSongTypeLabel(song: VideoItem | undefined): string {
+    if (!song) {
+      return '--';
+    }
+    if (song.type === CommonConstants.TYPE_LOCAL) {
+      return '本地';
+    }
+    if (song.type === CommonConstants.TYPE_WEBDAV) {
+      return 'WebDAV';
+    }
+    if (song.type === CommonConstants.TYPE_JELLYFIN) {
+      return 'Jellyfin';
+    }
+    if (song.type === CommonConstants.TYPE_EMBY) {
+      return 'Emby';
+    }
+    if (song.type === CommonConstants.TYPE_AUDIOSTATION) {
+      return 'AudioStation';
+    }
+    if (song.type === CommonConstants.TYPE_BAIDU) {
+      return '百度网盘';
+    }
+    if (song.type === CommonConstants.TYPE_NAVIDROME) {
+      return 'Navidrome';
+    }
+    if (song.type === CommonConstants.TYPE_PLEX) {
+      return 'Plex';
+    }
+    return `${song.type}`;
+  }
+
+  @Builder
+  private SongPropertyRow(label: string, value: string) {
+    Column({ space: 4 }) {
+      Text(label)
+        .fontSize(12)
+        .fontColor($r('app.color.index_tab_font_color'))
+        .opacity(0.7)
+      Text(value)
+        .fontSize(14)
+        .fontColor($r('app.color.text_color'))
+        .maxLines(6)
+        .textOverflow({ overflow: TextOverflow.Ellipsis })
+    }
+    .width('100%')
+    .alignItems(HorizontalAlign.Start)
+    .padding({ left: 2, right: 2, top: 4, bottom: 4 })
+  }
+
+  @Builder
+  private SongPropertySheetBuilder() {
+    if (this.songForPropertySheet) {
+      Column({ space: 10 }) {
+        this.SongPropertyRow('歌曲名称', this.getSongPropertyValue(this.songForPropertySheet?.name))
+        this.SongPropertyRow('文件名称', this.getSongPropertyValue(this.songForPropertySheet?.fileName))
+        this.SongPropertyRow('艺术家', this.getSongPropertyValue(this.songForPropertySheet?.artist))
+        this.SongPropertyRow('专辑', this.getSongPropertyValue(this.songForPropertySheet?.album))
+        this.SongPropertyRow('时长', this.getSongPropertyValue(this.songForPropertySheet?.duration))
+        this.SongPropertyRow('文件大小', this.getSongPropertyValue(this.songForPropertySheet?.size))
+        this.SongPropertyRow('比特率', this.getSongPropertyValue(this.songForPropertySheet?.bit_rate))
+        this.SongPropertyRow('采样率', this.getSongPropertyValue(this.songForPropertySheet?.sampleRate))
+        this.SongPropertyRow('声道数', this.getSongPropertyValue(this.songForPropertySheet?.channels))
+        this.SongPropertyRow('编码类型', this.getSongPropertyValue(this.songForPropertySheet?.mimeType))
+        this.SongPropertyRow('创建时间', this.getSongPropertyValue(this.songForPropertySheet?.cTime))
+        this.SongPropertyRow('来源类型', this.getSongTypeLabel(this.songForPropertySheet))
+        this.SongPropertyRow('文件路径', this.getSongPropertyValue(this.songForPropertySheet?.filePath))
+      }
+      .width('100%')
+      .padding({ left: 12, right: 12, top: 8, bottom: 12 })
+    } else {
+      Column() {
+        Text('暂无歌曲属性信息')
+          .fontSize(14)
+          .fontColor($r('app.color.text_color'))
+          .opacity(0.65)
+      }
+      .width('100%')
+      .height('100%')
+      .justifyContent(FlexAlign.Center)
+      .alignItems(HorizontalAlign.Center)
+    }
+  }
+
   build() {
     Stack() {
       if (this.accounts.length === 0) {
@@ -2394,6 +2497,14 @@ export struct WebDavMainPage {
     .backgroundImagePosition(Alignment.Center)
     .backdropBlur(this.blurValue)
     .backgroundBrightness({rate:this.isCustomizeBg?0.1:0,lightUpDegree:this.bgBrightness})
+    .bindSheet($$this.isShowSongPropertySheet, this.SongPropertySheetBuilder(), {
+      height: '88%',
+      dragBar: true,
+      showClose: true,
+      preferType: SheetType.CENTER,
+      blurStyle: BlurStyle.Thin,
+      title: { title: '歌曲属性' }
+    })
     .bindContentCover($$this.isShowDownloadCenter, this.DownloadCenterBuilder(), {
       transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
     })
@@ -2840,6 +2951,14 @@ export struct WebDavMainPage {
             .onClick(async () => {
               await this.enqueueSongDownload(song);
             })
+          //属性
+          MenuItem({
+            symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.music_note_list')),
+            content: '属性'
+          })
+            .onClick(() => {
+              this.openSongPropertySheet(song);
+            })
           //删除
           MenuItem({
             symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.trash')),