Эх сурвалжийг харах

艺术家专辑增加按数量升降序,播放全部增加随机播放

onecold 10 сар өмнө
parent
commit
b908cfd32c

+ 16 - 0
entry/src/main/ets/common/util/Utility.ets

@@ -1175,7 +1175,23 @@ export class Utility {
     }
     return list
   }
+  //以下是实现 getPlayItem 方法的代码,根据 playType 的值返回随机项或第一项
+  static getPlayItem(localList: Array<VideoItem>, playType: number): VideoItem | undefined {
+    // 处理空列表情况
+    if (!localList || localList.length  === 0) {
+      return undefined;
+    }
 
+    // 当 playType 为 3 时随机返回一个元素
+    if (playType === 3) {
+      const randomIndex = Math.floor(Math.random()  * localList.length);
+      return localList[randomIndex];
+    }
+    // 其他情况返回第一个元素
+    else {
+      return localList[0];
+    }
+  }
 
   //根据filePath获取当前索引index
   static getCurIndexFromGlobalList(localList:Array<VideoItem>,filePath:string){

+ 2 - 2
entry/src/main/ets/view/FixMessyView.ets

@@ -270,7 +270,7 @@ export struct FixMessyView {
       await Promise.all(embedTasks);
     } catch (error) {
       this.onFixResult(false)
-      console.error(`批量嵌入过程出错: ${JSON.stringify(error)}`);
+      console.error(`批量修复过程出错: ${JSON.stringify(error)}`);
     } finally {
       ToastUtil.showToast(`修复完成: 成功 ${this.embedSuccessCount}, 失败 ${this.embedFailedCount}`)
       this.isEmbedding = false;
@@ -278,7 +278,7 @@ export struct FixMessyView {
       this.totalFiles = this.selectedFiles.length;
       this.onFixResult(true)
       // 可以在这里添加完成后的提示或回调
-      console.info(`嵌入完成: 成功 ${this.embedSuccessCount}, 失败 ${this.embedFailedCount}`);
+      console.info(`修复完成: 成功 ${this.embedSuccessCount}, 失败 ${this.embedFailedCount}`);
     }
   }
 

+ 52 - 8
entry/src/main/ets/view/LocalMusic.ets

@@ -1285,7 +1285,7 @@ export struct LocalMusic {
   }
 
   showRankDialog() {
-    if (this.modeType === 2 || this.modeType === 3) {
+    if ((this.modeType === 2&&!this.isCanBack) || (this.modeType === 3&&!this.isCanBack)) {
       //动作面板
       DialogHelper.showBottomSheetDialog({
         title: "请选择排序模式",
@@ -1294,9 +1294,11 @@ export struct LocalMusic {
         sheets: [
           { value: '按名称升序', fontColor: $r('app.color.text_color') },
           { value: '按名称降序', fontColor: $r('app.color.text_color') },
+          { value: '按数量升序', fontColor: $r('app.color.text_color') },
+          { value: '按数量降序', fontColor: $r('app.color.text_color') },
         ],
         backgroundColor: $r('app.color.bg_card'),
-        height: '30%',
+        height: '45%',
         transition: AnimationHelper.transitionInDown(555),
         onAction: (index) => {
           switch (index) {
@@ -1306,6 +1308,45 @@ export struct LocalMusic {
             case 1:
               Utility.doSortListDescending(this.videoLocalList,this.isShowFileName)
               break;
+            case 2:
+              this.videoLocalList.sort((a:  VideoItem, b: VideoItem): number => {
+                // 1. Sort by type first
+                const typeOrder: number = getTypeOrder(a.type)  - getTypeOrder(b.type);
+                if (typeOrder !== 0) {
+                  return typeOrder;
+                }
+
+                // 2. Then sort by artist count (numeric comparison)
+                let  sortMap:Map<string, VideoItem[]>= new Map<string, VideoItem[]>();
+                if(this.modeType === 2){
+                  sortMap = this.artistMap
+                }else{
+                  sortMap = this.albumMap
+                }
+                const aArtistCount: number = sortMap.get(a.name)?.length  || 0;
+                const bArtistCount: number = sortMap.get(b.name)?.length  || 0;
+                return aArtistCount - bArtistCount;
+              });
+              break;
+            case 3:
+              this.videoLocalList.sort((a:  VideoItem, b: VideoItem): number => {
+                // 1. Sort by type first
+                const typeOrder: number = getTypeOrder(a.type)  - getTypeOrder(b.type);
+                if (typeOrder !== 0) {
+                  return typeOrder;
+                }
+
+                let  sortMap:Map<string, VideoItem[]>= new Map<string, VideoItem[]>();
+                if(this.modeType === 2){
+                  sortMap = this.artistMap
+                }else{
+                  sortMap = this.albumMap
+                }
+                const aArtistCount: number = sortMap.get(a.name)?.length  || 0;
+                const bArtistCount: number = sortMap.get(b.name)?.length  || 0;
+                return bArtistCount - aArtistCount;
+              });
+              break;
           }
           this.updateListData(this.videoLocalList)
         }
@@ -3238,17 +3279,19 @@ export struct LocalMusic {
         })
         .onClick(() => {
           // ToastUtil.showToast('当前的手机的折叠状态 ='+DisplayUtil.getFoldStatus())
-          if (this.modeType === 0) {
-            if (ArrayUtil.isNotEmpty(this.getCurFileList())) {
-              this.doPlay(this.getCurFileList()[0])
+          if (this.modeType  === 0) {
+            const playList = this.getCurFileList();
+            const item = Utility.getPlayItem(playList,  this.playType);
+            if (item) { // 显式检查undefined
+              this.doPlay(item);
             }
           } else {
-            if (ArrayUtil.isNotEmpty(this.mediaKuList)) {
-              this.doPlay(this.mediaKuList[0])
+            const item = Utility.getPlayItem(this.mediaKuList,  this.playType);
+            if (item) {
+              this.doPlay(item);
             }
           }
 
-
         })
 
         Row() {
@@ -4866,6 +4909,7 @@ export struct LocalMusic {
   }
 
   private doPlay(item: VideoItem, index?: number, isFromSonPlayList?: boolean,isOpen?:boolean) {
+
     switch (item.type) {
       case CommonConstants.TYPE_IS_DIR:
         // 进入歌单前安全保存当前滚动偏移量,支持列表和网格