Bläddra i källkod

设置可以开关定位歌曲的Button

onecold 6 månader sedan
förälder
incheckning
fe6f71c7cf
2 ändrade filer med 57 tillägg och 10 borttagningar
  1. 33 1
      entry/src/main/ets/pages/SettingPage.ets
  2. 24 9
      entry/src/main/ets/view/LocalMusic.ets

+ 33 - 1
entry/src/main/ets/pages/SettingPage.ets

@@ -32,6 +32,7 @@ import { audio } from '@kit.AudioKit'
 // @Entry
 @Component
 export struct SettingPage {
+  @State showFindLocation: boolean = true
   @State showZMIndex: boolean = false //是否右侧显示字母索引
   @State autoHideTitle: boolean = true //滚动自动隐藏标题栏
   @State isNoJumpToHome: boolean = false //网盘播放不跳转首页
@@ -258,6 +259,7 @@ export struct SettingPage {
   // 组件生命周期
   aboutToAppear() {
     this.defalut_home_type = PreferencesUtil.getNumberSync('defalut_home_type', 0)
+    this.showFindLocation  = PreferencesUtil.getBooleanSync('showFindLocation', true)
     this.showZMIndex = PreferencesUtil.getBooleanSync('showZMIndex', false)
     this.autoHideTitle = PreferencesUtil.getBooleanSync('autoHideTitle', true)
     this.isShowPrecious = PreferencesUtil.getBooleanSync('isShowPrecious', false)
@@ -2334,6 +2336,36 @@ export struct SettingPage {
 
       Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
+
+      Row() {
+        SymbolGlyph($r('sys.symbol.local_fill'))
+          .fontSize(20)
+          .fontColor([this.themeColor])
+          .alignSelf(ItemAlign.Center)
+          .margin({ left: 15 })
+        Text('定位歌曲按钮')
+          .margin({ left: 8 })
+          .fontSize(15)
+          .fontColor(Color.Gray)
+          .fontWeight(480)
+          .layoutWeight(1)
+        Toggle({ type: ToggleType.Switch, isOn: this.showFindLocation })
+          .selectedColor(this.themeColor)
+          .switchPointColor(Color.White)
+          .margin({ right: 18 })
+          .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
+          .onChange((checked: boolean) => {
+            this.showFindLocation = checked;
+            PreferencesUtil.put('showFindLocation', this.showFindLocation)
+            this.sendChangeEvent()
+          })
+          .width(50)
+          .height(30);
+      }
+      .height(55)
+      .clickEffect({ level: ClickEffectLevel.HEAVY })
+
+      Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
       // 播放页单行歌词
       Row() {
         SymbolGlyph($r('sys.symbol.close_sidebar'))
@@ -2433,7 +2465,7 @@ export struct SettingPage {
           .fontColor([this.themeColor])
           .alignSelf(ItemAlign.Center)
           .margin({ left: 15 })
-        Text('显示播放页返回键')
+        Text('播放页返回键')
           .margin({ left: 8 })
           .fontSize(15)
           .fontColor(Color.Gray)

+ 24 - 9
entry/src/main/ets/view/LocalMusic.ets

@@ -1135,6 +1135,7 @@ export struct LocalMusic {
     this.enablePointLight = PreferencesUtil.getBooleanSync('enablePointLight', true)
     AppStorage.setOrCreate('EnablePointLight', this.enablePointLight);
     this.showSimple = PreferencesUtil.getBooleanSync('showSimple', true)
+    this.showFindLocation  = PreferencesUtil.getBooleanSync('showFindLocation', true)
     this.showZMIndex = PreferencesUtil.getBooleanSync('showZMIndex', false)
     this.autoHideTitle = PreferencesUtil.getBooleanSync('autoHideTitle', true)
     this.isShowPrecious = PreferencesUtil.getBooleanSync('isShowPrecious', false)
@@ -3380,13 +3381,12 @@ export struct LocalMusic {
 
           PointLightDefaultButton({
             isSysBol:true,
-            pointColor:Color.Black,
+            pointColor:Color.Gray,
             imageResource:$r('sys.symbol.local_fill'),
             isPx: false,
             builderHeight: 30,
             builderWidth: 30,
           })
-          // ListLocateButton()
             .onClick(() =>{
               void this.locateCurrentSong();
             })
@@ -3398,8 +3398,9 @@ export struct LocalMusic {
 
       }
       .padding({
-        bottom: 0,right:5
+        bottom: 0
       })
+      .margin({right:5})
       .position({x:'92%'})
       .height('100%')
       .justifyContent(FlexAlign.Center)
@@ -7052,14 +7053,25 @@ export struct LocalMusic {
 
   }
 
-  scrollIndexMain(){
+  scrollIndexMain(dialogId?:string){
     try {
       setTimeout(() => {
         this.getUIContext()?.animateTo({ duration: 555 }, () => {
-          if(this.curIndex>60){
-            this.listScroller.scrollToIndex(this.curIndex,false, ScrollAlign.CENTER)
+          console.info('heanup scrollIndexMain this.curIndex='+this.curIndex)
+          if(dialogId)
+            DialogHelper.closeDialog(dialogId)
+          let isAni:boolean = false
+          if(this.curIndex<50){
+            isAni = true
+          }
+          if(this.twoFingerType==4){
+            this.waterScroller.scrollToIndex(this.curIndex,isAni, ScrollAlign.CENTER)
           }else{
-            this.listScroller.scrollToIndex(this.curIndex,true, ScrollAlign.CENTER)
+            if(this.isGridMusic){
+              this.scroller.scrollToIndex(this.curIndex,isAni, ScrollAlign.CENTER)
+            }else{
+              this.listScroller.scrollToIndex(this.curIndex,isAni, ScrollAlign.CENTER)
+            }
           }
 
         })
@@ -7084,13 +7096,16 @@ export struct LocalMusic {
       // 歌曲在当前列表中,直接滚动
       console.info("heanup locateCurrentSong: 找到歌曲,索引=" + targetIndex);
       this.curIndex = targetIndex;
+      this.scrollIndexMain();
     } else {
       // 歌曲不在当前列表中,加载当前歌曲再第几页完整列表后再定位
       console.info("heanup locateCurrentSong: 歌曲不在当前列表,开始加载完整列表");
+      const dialogID = DialogHelper.showLoadingDialog()
       await this.hydrateFullMediaPlayListIfNeeded(false);
-
+      this.curIndex  = Utility.getIndexFromList(this.videoLocalList, this.currentSong.filePath);
+      this.scrollIndexMain(dialogID);
     }
-    this.scrollIndexMain();
+
   }
 
   //播放列表布局