onecold пре 7 месеци
родитељ
комит
69f9ffebdf
1 измењених фајлова са 58 додато и 18 уклоњено
  1. 58 18
      entry/src/main/ets/view/LocalMusic.ets

+ 58 - 18
entry/src/main/ets/view/LocalMusic.ets

@@ -540,35 +540,37 @@ export struct LocalMusic {
 
     Logger.info('heanup LocalMusic', `onModeChange: 切换模式 modeType=${this.modeType}`);
 
-    // 模式切换时重置分页状态并加载第一页
-    await this.resetAndLoadFirstPage();
 
     switch (this.modeType) {
       case 0:
         // 首页模式已在 resetAndLoadFirstPage 中处理
+        // 切换模式时加载对应的排序类型
+        this.sortType = this.loadSortTypeForCurrentMode()
         break
       case 1:
         this.rightTopImage = $r('sys.symbol.sort')
         this.titleName = Utility.resourceToString(this.context,$r('app.string.media_ku'))
+        // 切换模式时加载对应的排序类型
+        this.sortType = this.loadSortTypeForCurrentMode()
         break
       case 2:
         this.rightTopImage = $r('sys.symbol.sort')
-        if (this.sortType === 4) {
-          this.sortType = 9
-          PreferencesUtil.putSync(SettingPage.SORT_TYPE, 9)
-        }
         this.titleName = Utility.resourceToString(this.context,$r('app.string.artist'))
+        // 切换到艺术家模式时,加载艺术家模式的排序类型(默认按数量降序)
+        this.sortType = this.loadSortTypeForCurrentMode()
         break
 
       case 3:
         this.rightTopImage = $r('sys.symbol.sort')
-        if (this.sortType === 4) {
-          this.sortType = 9
-          PreferencesUtil.putSync(SettingPage.SORT_TYPE, 9)
-        }
         this.titleName = Utility.resourceToString(this.context,$r('app.string.album'))
+        // 切换到专辑模式时,加载专辑模式的排序类型(默认按数量降序)
+        this.sortType = this.loadSortTypeForCurrentMode()
         break
     }
+    // 模式切换时重置分页状态并加载第一页
+    await this.resetAndLoadFirstPage();
+
+    Logger.info('heanup onModeChange', `doSortType: 切换排序方式 sortType=${this.sortType}, mode=${this.modeType}`);
   }
   // @Consume currentSong: VideoItem | undefined;
   @StorageLink('currentSong') currentSong: VideoItem | undefined = undefined;
@@ -2099,7 +2101,8 @@ export struct LocalMusic {
           pageIndex,
           pageSize: this.pageSize,
           sortType: this.sortType,
-          searchKeyword: this.isSearchMode ? this.searchText : undefined
+          searchKeyword: this.isSearchMode ? this.searchText : undefined,
+          isShowFileName: this.isShowFileName
         });
         if (result.items.length === 0) {
           break;
@@ -2225,12 +2228,45 @@ export struct LocalMusic {
     Logger.info('heanup LocalMusic', `doSortType: 切换排序方式 sortType=${index}, mode=${this.modeType}`);
 
     this.sortType = index;
-    PreferencesUtil.putSync(SettingPage.SORT_TYPE, index);
+    this.saveSortTypeForCurrentMode(index);
 
     // 分页模式下,排序需要重新从数据库查询
     await this.resetAndLoadFirstPage();
   }
 
+  /**
+   * 根据当前模式保存排序类型到不同的存储键
+   */
+  private saveSortTypeForCurrentMode(sortType: number): void {
+    let storageKey = SettingPage.SORT_TYPE;
+    if (this.modeType === 2) {
+      storageKey = 'SORT_TYPE_ARTIST';
+    } else if (this.modeType === 3) {
+      storageKey = 'SORT_TYPE_ALBUM';
+    } else {
+      storageKey = SettingPage.SORT_TYPE;
+    }
+    PreferencesUtil.putSync(storageKey, sortType);
+  }
+
+  /**
+   * 根据当前模式加载排序类型
+   */
+  private loadSortTypeForCurrentMode(): number {
+    let storageKey = SettingPage.SORT_TYPE;
+    let defaultSortType = 4;
+
+    if (this.modeType === 2) {
+      storageKey = 'SORT_TYPE_ARTIST';
+      defaultSortType = 9; // 艺术家模式默认按数量降序
+    } else if (this.modeType === 3) {
+      storageKey = 'SORT_TYPE_ALBUM';
+      defaultSortType = 9; // 专辑模式默认按数量降序
+    }
+
+    return PreferencesUtil.getNumberSync(storageKey, defaultSortType);
+  }
+
   showSheelDialog() {
     // if(PreferencesUtil.getBooleanSync('isFirstMusic',true)) {
     //   this.showTips()
@@ -3353,7 +3389,8 @@ export struct LocalMusic {
         pageIndex: 0,
         pageSize: this.totalCount,
         sortType: this.sortType,
-        searchKeyword: this.isSearchMode ? this.searchText : undefined
+        searchKeyword: this.isSearchMode ? this.searchText : undefined,
+        isShowFileName: this.isShowFileName
       };
       if (this.modeType === 0) {
         options.parentPath = this.currentPath;
@@ -3483,7 +3520,8 @@ export struct LocalMusic {
       pageIndex: 0,
       pageSize: this.totalCount,
       sortType: this.sortType,
-      searchKeyword: this.isSearchMode ? this.searchText : undefined
+      searchKeyword: this.isSearchMode ? this.searchText : undefined,
+      isShowFileName: this.isShowFileName
     })
     let alphabetSet = new Set<string>()
     for (let song of result.items) {
@@ -6632,7 +6670,7 @@ export struct LocalMusic {
         }
         let mList = this.artistMap.get(item.name)
         if (mList === undefined || ArrayUtil.isEmpty(mList)) {
-          mList = await this.table.querySongsByArtist(item.name, this.sortType);
+          mList = await this.table.querySongsByArtist(item.name, this.sortType, this.isShowFileName);
           if (ArrayUtil.isNotEmpty(mList)) {
             this.artistMap.set(item.name, mList);
           }
@@ -6704,7 +6742,7 @@ export struct LocalMusic {
         }
         let albumList = this.albumMap.get(item.name)
         if (albumList === undefined || ArrayUtil.isEmpty(albumList)) {
-          albumList = await this.table.querySongsByAlbum(item.name, this.sortType);
+          albumList = await this.table.querySongsByAlbum(item.name, this.sortType, this.isShowFileName);
           if (ArrayUtil.isNotEmpty(albumList)) {
             this.albumMap.set(item.name, albumList);
           }
@@ -7094,7 +7132,8 @@ export struct LocalMusic {
         pageIndex: pageIndex,
         pageSize: this.pageSize,
         sortType: this.sortType,
-        searchKeyword: this.isSearchMode ? this.searchText : undefined
+        searchKeyword: this.isSearchMode ? this.searchText : undefined,
+        isShowFileName: this.isShowFileName
       };
 
       // 根据 modeType 补充查询条件
@@ -7215,7 +7254,8 @@ export struct LocalMusic {
         pageIndex: nextPage,
         pageSize: this.pageSize,
         sortType: this.sortType,
-        searchKeyword: this.isSearchMode ? this.searchText : undefined
+        searchKeyword: this.isSearchMode ? this.searchText : undefined,
+        isShowFileName: this.isShowFileName
       };
       let result: PageQueryResult = { items: [], totalCount: 0, hasMore: false };
       if (this.modeType === 2) {