Просмотр исходного кода

设置增加右侧字母索引是否显示

onecold 8 месяцев назад
Родитель
Сommit
979c7d9f82

+ 4 - 8
entry/src/main/ets/pages/NewIndex.ets

@@ -1136,15 +1136,11 @@ struct NewIndex {
   }
 
   isTextSelected(index:number):boolean{
-    if(this.isShowTitleBar&&!this.isHiCar()){
-        return this.mType ==index
-    }else{
-      if(this.mType == 0){
-        return this.modeType == index
-      }
-      return this.mType+3 == index
+    if(this.mType == 0){
+      return this.modeType == index
     }
-    return false
+    return this.mType+3 == index
+
   }
 
   doShowDrawer(){

+ 32 - 60
entry/src/main/ets/pages/SettingPage.ets

@@ -32,6 +32,7 @@ import { audio } from '@kit.AudioKit'
 // @Entry
 @Component
 export struct SettingPage {
+  @State showZMIndex: boolean = false //是否右侧显示字母索引
   @State autoHideTitle: boolean = true //滚动自动隐藏标题栏
   @State isNoJumpToHome: boolean = false //网盘播放不跳转首页
   @State iconCurrentID: string = 'default';//图标的id
@@ -255,7 +256,7 @@ export struct SettingPage {
 
   // 组件生命周期
   aboutToAppear() {
-    // this.geIDD()
+    this.showZMIndex = PreferencesUtil.getBooleanSync('showZMIndex', false)
     this.autoHideTitle = PreferencesUtil.getBooleanSync('autoHideTitle', true)
     this.isShowPrecious = PreferencesUtil.getBooleanSync('isShowPrecious', false)
     this.isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
@@ -2291,65 +2292,36 @@ export struct SettingPage {
 
       Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
-      // Row() {
-      //   SymbolGlyph($r('sys.symbol.label'))
-      //     .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.isShowAllBar })
-      //     .selectedColor(this.themeColor)
-      //     .switchPointColor(Color.White)
-      //     .margin({ right: 18 })
-      //     .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
-      //     .onChange((checked: boolean) => {
-      //       this.isShowAllBar = checked;
-      //       PreferencesUtil.put(SettingPage.IS_SHOW_ALLBAR, this.isShowAllBar)
-      //       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.lock'))
-      //     .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.isShowSimi })
-      //     .selectedColor(this.themeColor)
-      //     .switchPointColor(Color.White)
-      //     .margin({ right: 18 })
-      //     .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
-      //     .onChange((checked: boolean) => {
-      //       this.isShowSimi = checked;
-      //       PreferencesUtil.put(SettingPage.IS_SHOW_SIMI, this.isShowSimi)
-      //       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.label'))
+          .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.showZMIndex })
+          .selectedColor(this.themeColor)
+          .switchPointColor(Color.White)
+          .margin({ right: 18 })
+          .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
+          .onChange((checked: boolean) => {
+            this.showZMIndex = checked;
+            PreferencesUtil.put('showZMIndex', this.showZMIndex)
+            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'))

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

@@ -752,6 +752,7 @@ const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
 @Preview
 @Component
 export struct LocalMusic {
+  @State showZMIndex: boolean = false //是否右侧显示字母索引
   private prevOffsetY: number = 0; // 记录上一次的Y轴偏移量
   @State autoHideTitle: boolean = true //滚动自动隐藏标题栏
   // 字母表
@@ -1331,7 +1332,10 @@ export struct LocalMusic {
     let audioRoutingManager = audioManager.getRoutingManager();  // 再调用AudioManager的方法创建AudioRoutingManager实例。
     audioRoutingManager.on('deviceChange', audio.DeviceFlag.INPUT_DEVICES_FLAG, (deviceChanged: audio.DeviceChangeAction) => {
       console.info('device change type : ' + deviceChanged.type);  // 设备连接状态变化,0为连接,1为断开连接。
-      if(deviceChanged.type==1){
+      // 设备类型 22是USB耳机,带麦克风,3是有线耳机。
+      if(deviceChanged.type==1&&
+        (deviceChanged.deviceDescriptors[0].deviceType== 22||
+          deviceChanged.deviceDescriptors[0].deviceType==3)){
         this.pause();
       }
     });
@@ -1484,6 +1488,7 @@ export struct LocalMusic {
     context.getApplicationContext().setColorMode(colorMode)
   }
   initSetting() {
+    this.showZMIndex = PreferencesUtil.getBooleanSync('showZMIndex', false)
     this.autoHideTitle = PreferencesUtil.getBooleanSync('autoHideTitle', true)
     this.isShowPrecious = PreferencesUtil.getBooleanSync('isShowPrecious', false)
     this.sortType = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
@@ -3540,7 +3545,9 @@ export struct LocalMusic {
               }
             })
             // 右侧居中的字母表索引
-            this.indexBuilder()
+            if(this.showZMIndex){
+              this.indexBuilder()
+            }
 
             this.topTitleBar()
           }
@@ -3827,6 +3834,9 @@ export struct LocalMusic {
   }
 
   async setAlphaBet(){
+    if(!this.showZMIndex){
+        return
+    }
     return new Promise<void>((resolve,reject) => {
       try {
         let songs = this.videoLocalList
@@ -13925,7 +13935,6 @@ export struct LocalMusic {
 
     this.mIjkMediaPlayer.start();
 
-
   }
 
   //保存最后播放的那首歌和已经对应的播放列表