Quellcode durchsuchen

优化NavidRome界面,点击头像播放可以直接跳转到播放页,点击其他位置不跳转

onecold vor 9 Monaten
Ursprung
Commit
15f8213f87

+ 5 - 2
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -477,7 +477,7 @@ export struct WebDavMainPage {
   }
 
   // 播放WebDAV歌曲
-  private playSong(song: VideoItem, index: number): void {
+  private playSong(song: VideoItem, index: number,isJump?:boolean): void {
     try {
       Logger.info(TAG, `heanup === WebDAV playSong 方法被调用 ===`);
       Logger.info(TAG, 'heanup 播放指定歌曲: ' + song.name + ', 索引: ' + index);
@@ -531,7 +531,7 @@ export struct WebDavMainPage {
 
       Logger.info(TAG, `heanup 发送WebDAV播放事件,只传递索引: ${index}`);
 
-      if(!this.isNoJumpToHome){
+      if(!this.isNoJumpToHome||isJump){
         // 跳转到首页播放器
         this.getUIContext()?.animateTo({ duration: 555 }, () => {
           this.mType = 0
@@ -1225,6 +1225,9 @@ export struct WebDavMainPage {
           .fillColor(this.themeColor)
           .objectFit(ImageFit.Cover)
           .margin({ left: 8 })
+          .onClick(() => {
+            this.playSong(song, index, true);
+          })
 
         // 歌曲信息
         Column({ space: 4 }) {

+ 3 - 4
entry/src/main/ets/view/LocalMusic.ets

@@ -15153,7 +15153,7 @@ export struct LocalMusic {
           // 验证webdav_account_id设置情况
           const accountIds = videoItems.map(item => item.webdav_account_id).filter(id => id);
           Logger.info(`heanup 有 ${accountIds.length}/${videoItems.length} 首歌曲设置了webdav_account_id`)
-
+          this.setShowPlayTrue()//显示播放页
           this.finishLoadingPlaylist(videoItems, currentPlayIndex, playlistName)
           return
         } else {
@@ -15167,6 +15167,7 @@ export struct LocalMusic {
         const currentPlayIndex = getNavidromeCurrentPlayIndex();
         Logger.info(`heanup Navidrome歌曲列表长度: ${videoItems.length}`);
         if (videoItems && videoItems.length > 0) {
+          this.setShowPlayTrue()//显示播放页
           this.finishLoadingPlaylist(videoItems, currentPlayIndex, playlistName);
           return;
         } else {
@@ -15174,7 +15175,6 @@ export struct LocalMusic {
           return;
         }
       }
-
       // 从数据库重新加载这些歌曲,使用索引记录位置以保持顺序
       const songMap: Map<number, VideoItem> = new Map()
       let completedQueries = 0
@@ -15216,7 +15216,6 @@ export struct LocalMusic {
                 // Logger.info(`heanup 按顺序添加歌曲[${j}]: ${song.name}`)
               }
             }
-
             Logger.info(`heanup 最终歌曲列表顺序: ${songs.map((s, idx) => `[${idx}]${s.name}`).join(', ')}`)
             this.finishLoadingPlaylist(songs, startIndex, playlistName)
           }
@@ -15273,7 +15272,7 @@ export struct LocalMusic {
 
     PreferencesUtil.putSync('LastMusicList', this.songList)
 
-    ToastUtil.showToast(`开始播放歌单: ${playlistName}`)
+    // ToastUtil.showToast(`开始播放歌单: ${playlistName}`)
   }
 }
 //视频气泡窗口的布局

+ 57 - 36
entry/src/main/ets/view/NavidromePage.ets

@@ -40,6 +40,7 @@ export struct NavidromePage {
   @Link mType: number;
   @Link offsetX: number;
   @Link isShowDrawer: boolean;
+  @State isNoJumpToHome: boolean = false //网盘播放不跳转首页
   @Prop @Watch('onSwitchAccount') selectedAccount: WebDavAccount;
   @StorageProp('currentTheme') currentTheme: number = 0;
   @State selectedTab: number = 0; // 0: 全部, 1: 艺术家, 2: 专辑
@@ -47,6 +48,7 @@ export struct NavidromePage {
   @State artists: NavidromeRestArtist[] = [];
   @State albums: NavidromeRestAlbum[] = [];
   @State loading: boolean = false;
+  @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
   @StorageProp('topRectHeight') topRectHeight: number = 0;
   @State @Watch('onTabSelectedIndexesChanged') tabSelectedIndexes: number[] = [0];
   @StorageProp('themeColor') themeColor: string =
@@ -62,11 +64,11 @@ export struct NavidromePage {
     buttons: [{ text: '全部' }, { text: '艺术家' }, { text: '专辑' }] as SegmentButtonItemTuple,
     direction: Direction.Ltr,
     buttonPadding: { top: 12, bottom: 12 },
-    backgroundColor: $r('app.color.start_window_background'),
+    backgroundColor: $r('app.color.index_background'),
+    selectedBackgroundColor: $r('app.color.start_window_background'),
+    selectedFontColor: $r('app.color.text_color'),
     fontSize: 14,
     selectedFontSize: 15,
-    selectedFontColor: Color.White,
-    selectedBackgroundColor: $r('app.color.title_bar_bg'),
     localizedTextPadding: {
       end: LengthMetrics.vp(20),
       start: LengthMetrics.vp(20)
@@ -85,6 +87,7 @@ export struct NavidromePage {
   }
 
   aboutToAppear() {
+    this.isNoJumpToHome = PreferencesUtil.getBooleanSync('isNoJumpToHome', true)
     this.refreshNavidromeData();
   }
 
@@ -195,7 +198,7 @@ export struct NavidromePage {
   @Builder
   topTitleBar() {
     Column() {
-      Row({ space: 15 }) {
+      Row({ space: 6 }) {
         // 左侧返回按钮
         Button({ type: ButtonType.Circle, stateEffect: true }) {
           SymbolGlyph($r('sys.symbol.sort'))
@@ -227,11 +230,9 @@ export struct NavidromePage {
             // 可以添加标题点击事件
           })
           .animation({ duration: 300, curve: Curve.Ease })
-
-
       }
       .width('100%')
-      .height(60)
+      .height(55)
       .padding({left: 15, right: 15})
       .justifyContent(FlexAlign.SpaceBetween)
       .alignItems(VerticalAlign.Center)
@@ -243,10 +244,9 @@ export struct NavidromePage {
       })
         .width('100%')
         .padding({ left: 25, right: 25, top: 5, bottom: 5 })
-        .margin({top:5})
     }
     .width('100%')
-    .padding({ top: this.topRectHeight+10})
+    .padding({ top: this.topRectHeight+5})
     .backgroundColor($r('app.color.start_window_background'))
   }
 
@@ -297,26 +297,29 @@ export struct NavidromePage {
           .fillColor(this.themeColor)
           .objectFit(ImageFit.Cover)
           .margin({ left: 8 })
+          .onClick(() => {
+            this.playSong(song, index, true);
+          })
 
         // 歌曲信息
         Column({ space: 4 }) {
           Text(song.name)
             .fontSize(15)
-            .fontColor(this.themeColor)
+            .fontColor(this.currentSong?.filePath==song.filePath?this.themeColor:$r('app.color.index_tab_font_color'))
             .maxLines(1)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
 
           Row(){
             Text((song.artist ?? '') + "  ")
               .fontSize(13)
-              .fontColor($r('app.color.index_tab_font_color'))
+              .fontColor(this.currentSong?.filePath==song.filePath?this.themeColor:$r('app.color.index_tab_font_color'))
               .opacity(0.6)
               .maxLines(1)
               .visibility(song.artist?Visibility.Visible:Visibility.None)
               .textOverflow({ overflow: TextOverflow.Ellipsis })
             Text(this.buildSongMetaLine(song))
               .fontSize(13)
-              .fontColor($r('app.color.index_tab_font_color'))
+              .fontColor(this.currentSong?.filePath==song.filePath?this.themeColor:$r('app.color.index_tab_font_color'))
               .opacity(0.6)
               .maxLines(1)
               .textOverflow({ overflow: TextOverflow.Ellipsis })
@@ -333,6 +336,8 @@ export struct NavidromePage {
             .duration(1000)// 持续
             .state(AnimationStatus.Running)// 动画状态
             .fillMode(FillMode.Forwards)
+            .visibility(this.currentSong?.filePath==song.filePath ?  Visibility.Visible :
+              Visibility.None)
             .width(18)
             .margin({ right: 12, top: 8, bottom: 8 })
             .height(18)
@@ -362,8 +367,9 @@ export struct NavidromePage {
         Column({ space: 4 }) {
           Text(artist.name ?? Constants.UNKNOWN_ARTIST)
             .fontSize(15)
-            .fontColor(this.themeColor)
+            .fontColor($r('app.color.index_tab_font_color'))
             .maxLines(1)
+            .textAlign(TextAlign.Start)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
 
           Text(this.buildArtistMetaLine(artist))
@@ -373,9 +379,11 @@ export struct NavidromePage {
             .maxLines(1)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
         }
-        .layoutWeight(1)
+        .alignItems(HorizontalAlign.Start)
         .padding({ right: 20 })
+
       }
+      .width('100%')
     }
     .width('100%')
     .padding(12)
@@ -399,27 +407,31 @@ export struct NavidromePage {
         Column({ space: 4 }) {
           Text(album.name ?? '未知专辑')
             .fontSize(15)
-            .fontColor(this.themeColor)
-            .maxLines(1)
-            .textOverflow({ overflow: TextOverflow.Ellipsis })
-
-          Text(album.artist ?? Constants.UNKNOWN_ARTIST)
-            .fontSize(13)
             .fontColor($r('app.color.index_tab_font_color'))
-            .opacity(0.6)
             .maxLines(1)
+            .textAlign(TextAlign.Start)
             .textOverflow({ overflow: TextOverflow.Ellipsis })
+          Row(){
+            Text(album.artist ?? Constants.UNKNOWN_ARTIST)
+              .fontSize(13)
+              .fontColor($r('app.color.index_tab_font_color'))
+              .opacity(0.6)
+              .maxLines(1)
+              .textOverflow({ overflow: TextOverflow.Ellipsis })
+
+            Text(this.buildAlbumMetaLine(album))
+              .fontSize(13)
+              .fontColor($r('app.color.index_tab_font_color'))
+              .opacity(0.6)
+              .maxLines(1)
+              .textOverflow({ overflow: TextOverflow.Ellipsis })
+          }
 
-          Text(this.buildAlbumMetaLine(album))
-            .fontSize(13)
-            .fontColor($r('app.color.index_tab_font_color'))
-            .opacity(0.6)
-            .maxLines(1)
-            .textOverflow({ overflow: TextOverflow.Ellipsis })
         }
-        .layoutWeight(1)
+        .alignItems(HorizontalAlign.Start)
         .padding({ right: 20 })
       }
+      .width('100%')
     }
     .width('100%')
     .padding(12)
@@ -493,11 +505,14 @@ export struct NavidromePage {
   }
 
   private applyFilter(type: NavFilterType, id: string, label: string): void {
-    this.filterType = type;
-    this.filterId = id;
-    this.filterLabel = label;
-    this.selectedTab = 0;
-    this.tabSelectedIndexes = [0];
+    this.getUIContext().animateTo({ duration: 555 }, () => {
+      this.filterType = type;
+      this.filterId = id;
+      this.filterLabel = label;
+      this.selectedTab = 0;
+      this.tabSelectedIndexes = [0];
+    })
+
   }
 
   private clearFilter(): void {
@@ -506,7 +521,7 @@ export struct NavidromePage {
     this.filterLabel = '';
   }
 
-  private playSong(song: VideoItem, index: number): void {
+  private playSong(song: VideoItem, index: number,isJump?:boolean): void {
     try {
       if (!this.allVideos || this.allVideos.length === 0) {
         ToastUtil.showToast('暂无可播放的歌曲');
@@ -531,7 +546,12 @@ export struct NavidromePage {
       const eventPlaylistPlay: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_PLAY };
       emitter.emit(eventPlaylistPlay, { data: playlistData });
       Logger.info('heanup', `Navidrome 发送播放事件,歌曲数: ${this.allVideos.length}, 起始: ${index}`);
-      this.mType = 0;
+      if(!this.isNoJumpToHome||isJump){
+        // 跳转到首页播放器
+        this.getUIContext()?.animateTo({ duration: 555 }, () => {
+          this.mType = 0
+        })
+      }
     } catch (error) {
       const err = error as Error;
       Logger.error('heanup', '播放歌曲失败: ' + err.message);
@@ -568,10 +588,11 @@ export struct NavidromePage {
               .layoutWeight(1)
             Button('清除筛选')
               .type(ButtonType.Capsule)
+              .backgroundColor(this.themeColor)
               .fontSize(12)
               .onClick(() => this.clearFilter())
           }
-          .width('100%')
+          .width('90%')
           .padding({ left: 16, right: 16, top: 6, bottom: 2 })
         }