Преглед изворни кода

初步实现字母表索引2

onecold пре 9 месеци
родитељ
комит
493585cda4
1 измењених фајлова са 29 додато и 6 уклоњено
  1. 29 6
      entry/src/main/ets/view/LocalMusic.ets

+ 29 - 6
entry/src/main/ets/view/LocalMusic.ets

@@ -571,7 +571,7 @@ export struct LocalMusic {
     'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
   @State alphaBetStyle: GlobalAlphabetIndexerModifier = new GlobalAlphabetIndexerModifier()
   @State selectAlphaBetIndex: number = 0
-  @State isShowAlphaBet: boolean = true
+  @State isShowAlphaBet: boolean = false
   @State isScrolling: boolean = false
   @State isTouchingAlphaBet: boolean = false
   @State alphabetHeight: number = 0
@@ -3462,6 +3462,28 @@ export struct LocalMusic {
       this.listScroller.scrollToIndex(targetIndex);
     }
   }
+  // 找到对应字母表的索引
+  findAlphaBetIndex(song: VideoItem):number{
+    let text = song.name
+    // if(this.sortMode === SortMode.ByArtist){
+    //   text = song.artist
+    // }else if(this.sortMode === SortMode.ByTitle){
+    //   text = song.title
+    // }else if(this.sortMode === SortMode.ByRoot){
+    //   text = song.webFilePath.replace('/','')
+    // }
+    const pyStr = song.pyStr
+    if(pyStr){
+      let firstLetter = pyStr[0]
+      for(let i=0;i<this.alphaBet.length;i++){
+        if(this.alphaBet[i] === firstLetter){
+          return i
+        }
+      }
+    }
+
+    return 0
+  }
 
   async setAlphaBet(){
     return new Promise<void>((resolve,reject) => {
@@ -6425,6 +6447,12 @@ export struct LocalMusic {
       this.isScrolling = true
       this.isShowAlphaBet = true
     })
+    .onScrollIndex((start: number,center:number,end:number) => {
+      this.selectedIndex = start
+      if(start >= 0 && start < this.videoLocalList.length){
+        this.selectAlphaBetIndex = this.findAlphaBetIndex(this.videoLocalList[start])
+      }
+    })
     .onScrollStop(() => {
       if(this.isScrolling){
         this.isScrolling = false
@@ -6450,12 +6478,7 @@ export struct LocalMusic {
     .cachedCount(10)
     // .reuseId('list_item')
     .borderRadius(20)
-    // .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 0.9, y: 0.9 }).animation({ duration: 400 }),
-    //   TransitionEffect.scale({ x: 0, y: 0 })))
     .layoutWeight(1)
-    .onScrollIndex((start) => {
-      this.selectedIndex = start
-    })
     .visibility(this.isGridMusic ? Visibility.None : Visibility.Visible)
     .lanes(
       new BreakpointType<number>({