|
@@ -703,8 +703,10 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
this.isZero = false
|
|
this.isZero = false
|
|
|
if (this.modeType !== 0 && this.isCanBack) {
|
|
if (this.modeType !== 0 && this.isCanBack) {
|
|
|
- this.onModeChange()
|
|
|
|
|
|
|
+ // 先设置 isCanBack=false,确保 onModeChange 读取的是列表页的排序设置
|
|
|
this.isCanBack = false
|
|
this.isCanBack = false
|
|
|
|
|
+ this.onModeChange()
|
|
|
|
|
+
|
|
|
// 返回专辑列表时恢复滚动偏移量,支持列表和网格
|
|
// 返回专辑列表时恢复滚动偏移量,支持列表和网格
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
if (this.modeType == 2) {
|
|
if (this.modeType == 2) {
|
|
@@ -2269,6 +2271,15 @@ export struct LocalMusic {
|
|
|
.onClick(async () => {
|
|
.onClick(async () => {
|
|
|
await this.doSortType(7)
|
|
await this.doSortType(7)
|
|
|
})
|
|
})
|
|
|
|
|
+ MenuItem({
|
|
|
|
|
+ symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.music')),
|
|
|
|
|
+ content: '按碟片编号-音轨号升序'
|
|
|
|
|
+ })
|
|
|
|
|
+ .onClick(async () => {
|
|
|
|
|
+ await this.doSortType(10)
|
|
|
|
|
+ })
|
|
|
|
|
+ .visibility((this.modeType==0||(this.modeType==3&&this.isCanBack))?Visibility.Visible:Visibility.None)
|
|
|
|
|
+
|
|
|
}.attributeModifier(new MenuModifier())
|
|
}.attributeModifier(new MenuModifier())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2305,48 +2316,119 @@ export struct LocalMusic {
|
|
|
.onClick(async () => {
|
|
.onClick(async () => {
|
|
|
await this.doSortType(9)
|
|
await this.doSortType(9)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
}.attributeModifier(new MenuModifier())
|
|
}.attributeModifier(new MenuModifier())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
async doSortType(index: number): Promise<void> {
|
|
async doSortType(index: number): Promise<void> {
|
|
|
- Logger.info('heanup LocalMusic', `doSortType: 切换排序方式 sortType=${index}, mode=${this.modeType}`);
|
|
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `doSortType: 切换排序方式 sortType=${index}, mode=${this.modeType}, isCanBack=${this.isCanBack}`);
|
|
|
|
|
|
|
|
this.sortType = index;
|
|
this.sortType = index;
|
|
|
this.saveSortTypeForCurrentMode(index);
|
|
this.saveSortTypeForCurrentMode(index);
|
|
|
|
|
|
|
|
- // 分页模式下,排序需要重新从数据库查询
|
|
|
|
|
- await this.resetAndLoadFirstPage();
|
|
|
|
|
|
|
+ // 详情页模式(modeType=2/3 且 isCanBack=true): 重新查询当前项目的歌曲
|
|
|
|
|
+ if (this.isCanBack && (this.modeType === 2 || this.modeType === 3)) {
|
|
|
|
|
+ await this.reloadCurrentDetailSongs();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 分页模式下,排序需要重新从数据库查询
|
|
|
|
|
+ await this.resetAndLoadFirstPage();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 重新加载当前详情页(专辑/艺术家)的歌曲数据
|
|
|
|
|
+ * 用于详情页切换排序方式时重新查询并排序
|
|
|
|
|
+ */
|
|
|
|
|
+ private async reloadCurrentDetailSongs(): Promise<void> {
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `reloadCurrentDetailSongs: modeType=${this.modeType}, titleName=${this.titleName}, sortType=${this.sortType}`);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.modeType === 2) {
|
|
|
|
|
+ // 艺术家详情页: 重新查询该艺术家的歌曲
|
|
|
|
|
+ const mList = await this.table.querySongsByArtist(this.titleName, this.sortType, this.isShowFileName);
|
|
|
|
|
+ if (ArrayUtil.isNotEmpty(mList)) {
|
|
|
|
|
+ // 使用带排序类型的缓存键
|
|
|
|
|
+ const cacheKey = `${this.titleName}_sort_${this.sortType}`;
|
|
|
|
|
+ this.artistMap.set(cacheKey, mList);
|
|
|
|
|
+ this.totalCount = mList.length;
|
|
|
|
|
+ // 使用 noSort=true 避免在 updateListData 中重新排序导致死循环
|
|
|
|
|
+ this.updateListData(mList, true);
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `reloadCurrentDetailSongs: 艺术家详情页重新加载完成, 歌曲数=${mList.length}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (this.modeType === 3) {
|
|
|
|
|
+ // 专辑详情页: 重新查询该专辑的歌曲
|
|
|
|
|
+ const albumList = await this.table.querySongsByAlbum(this.titleName, this.sortType, this.isShowFileName);
|
|
|
|
|
+ if (ArrayUtil.isNotEmpty(albumList)) {
|
|
|
|
|
+ // 使用带排序类型的缓存键
|
|
|
|
|
+ const cacheKey = `${this.titleName}_sort_${this.sortType}`;
|
|
|
|
|
+ this.albumMap.set(cacheKey, albumList);
|
|
|
|
|
+ this.totalCount = albumList.length;
|
|
|
|
|
+ // 使用 noSort=true 避免在 updateListData 中重新排序导致死循环
|
|
|
|
|
+ this.updateListData(albumList, true);
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `reloadCurrentDetailSongs: 专辑详情页重新加载完成, 歌曲数=${albumList.length}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ const error = err as Error;
|
|
|
|
|
+ Logger.error('heanup LocalMusic', `reloadCurrentDetailSongs error: ${error.message}`);
|
|
|
|
|
+ ToastUtil.showToast('重新加载数据失败');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据当前模式保存排序类型到不同的存储键
|
|
* 根据当前模式保存排序类型到不同的存储键
|
|
|
|
|
+ * 区分列表页和详情页的排序设置
|
|
|
*/
|
|
*/
|
|
|
private saveSortTypeForCurrentMode(sortType: number): void {
|
|
private saveSortTypeForCurrentMode(sortType: number): void {
|
|
|
let storageKey = SettingPage.SORT_TYPE;
|
|
let storageKey = SettingPage.SORT_TYPE;
|
|
|
if (this.modeType === 2) {
|
|
if (this.modeType === 2) {
|
|
|
- storageKey = 'SORT_TYPE_ARTIST';
|
|
|
|
|
|
|
+ // 艺术家模式
|
|
|
|
|
+ if (this.isCanBack) {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ARTIST_DETAIL'; // 艺术家详情页排序
|
|
|
|
|
+ } else {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ARTIST'; // 艺术家列表页排序
|
|
|
|
|
+ }
|
|
|
} else if (this.modeType === 3) {
|
|
} else if (this.modeType === 3) {
|
|
|
- storageKey = 'SORT_TYPE_ALBUM';
|
|
|
|
|
|
|
+ // 专辑模式
|
|
|
|
|
+ if (this.isCanBack) {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ALBUM_DETAIL'; // 专辑详情页排序
|
|
|
|
|
+ } else {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ALBUM'; // 专辑列表页排序
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
storageKey = SettingPage.SORT_TYPE;
|
|
storageKey = SettingPage.SORT_TYPE;
|
|
|
}
|
|
}
|
|
|
PreferencesUtil.putSync(storageKey, sortType);
|
|
PreferencesUtil.putSync(storageKey, sortType);
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `saveSortTypeForCurrentMode: mode=${this.modeType}, isCanBack=${this.isCanBack}, sortType=${sortType}, key=${storageKey}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据当前模式加载排序类型
|
|
* 根据当前模式加载排序类型
|
|
|
|
|
+ * 区分列表页和详情页的排序设置
|
|
|
*/
|
|
*/
|
|
|
private loadSortTypeForCurrentMode(): number {
|
|
private loadSortTypeForCurrentMode(): number {
|
|
|
let storageKey = SettingPage.SORT_TYPE;
|
|
let storageKey = SettingPage.SORT_TYPE;
|
|
|
let defaultSortType = 4;
|
|
let defaultSortType = 4;
|
|
|
|
|
|
|
|
if (this.modeType === 2) {
|
|
if (this.modeType === 2) {
|
|
|
- storageKey = 'SORT_TYPE_ARTIST';
|
|
|
|
|
- defaultSortType = 9; // 艺术家模式默认按数量降序
|
|
|
|
|
|
|
+ // 艺术家模式
|
|
|
|
|
+ if (this.isCanBack) {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ARTIST_DETAIL'; // 艺术家详情页排序
|
|
|
|
|
+ defaultSortType = 4; // 详情页默认按名称升序
|
|
|
|
|
+ } else {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ARTIST'; // 艺术家列表页排序
|
|
|
|
|
+ defaultSortType = 9; // 列表页默认按数量降序
|
|
|
|
|
+ }
|
|
|
} else if (this.modeType === 3) {
|
|
} else if (this.modeType === 3) {
|
|
|
- storageKey = 'SORT_TYPE_ALBUM';
|
|
|
|
|
- defaultSortType = 9; // 专辑模式默认按数量降序
|
|
|
|
|
|
|
+ // 专辑模式
|
|
|
|
|
+ if (this.isCanBack) {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ALBUM_DETAIL'; // 专辑详情页排序
|
|
|
|
|
+ defaultSortType = 4; // 详情页默认按名称升序
|
|
|
|
|
+ } else {
|
|
|
|
|
+ storageKey = 'SORT_TYPE_ALBUM'; // 专辑列表页排序
|
|
|
|
|
+ defaultSortType = 9; // 列表页默认按数量降序
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return PreferencesUtil.getNumberSync(storageKey, defaultSortType);
|
|
return PreferencesUtil.getNumberSync(storageKey, defaultSortType);
|
|
@@ -6679,15 +6761,32 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
|
|
this.mScrollMap.set('lastListArtistScrollOffset', offsetA)
|
|
|
}
|
|
}
|
|
|
- let mList = this.artistMap.get(item.name)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 进入艺术家详情页前,先加载详情页的排序类型
|
|
|
|
|
+ // 注意:需要临时设置isCanBack=true,以便loadSortTypeForCurrentMode读取详情页的排序设置
|
|
|
|
|
+ const artistOriginalIsCanBack = this.isCanBack;
|
|
|
|
|
+ this.isCanBack = true;
|
|
|
|
|
+ const artistDetailSortType = this.loadSortTypeForCurrentMode();
|
|
|
|
|
+ this.isCanBack = artistOriginalIsCanBack; // 恢复原值
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `进入艺术家详情页: 加载详情页排序 sortType=${artistDetailSortType}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 缓存键需要包含排序类型,因为不同的排序类型会产生不同的数据
|
|
|
|
|
+ const artistCacheKey = `${item.name}_sort_${artistDetailSortType}`;
|
|
|
|
|
+ let mList = this.artistMap.get(artistCacheKey)
|
|
|
|
|
+
|
|
|
if (mList === undefined || ArrayUtil.isEmpty(mList)) {
|
|
if (mList === undefined || ArrayUtil.isEmpty(mList)) {
|
|
|
- mList = await this.table.querySongsByArtist(item.name, this.sortType, this.isShowFileName);
|
|
|
|
|
|
|
+ // 使用详情页的排序类型查询
|
|
|
|
|
+ mList = await this.table.querySongsByArtist(item.name, artistDetailSortType, this.isShowFileName);
|
|
|
if (ArrayUtil.isNotEmpty(mList)) {
|
|
if (ArrayUtil.isNotEmpty(mList)) {
|
|
|
- this.artistMap.set(item.name, mList);
|
|
|
|
|
|
|
+ this.artistMap.set(artistCacheKey, mList);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 设置当前排序类型为详情页排序
|
|
|
|
|
+ this.sortType = artistDetailSortType;
|
|
|
|
|
+
|
|
|
if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
|
|
if (mList !== undefined && ArrayUtil.isNotEmpty(mList)) {
|
|
|
- Utility.doSortListAscending(mList)
|
|
|
|
|
|
|
+ // 注意:不再调用 Utility.doSortListAscending,因为数据已经按 artistDetailSortType 排序了
|
|
|
const nextArtistCountMap = new Map(this.artistSongCountMap);
|
|
const nextArtistCountMap = new Map(this.artistSongCountMap);
|
|
|
nextArtistCountMap.set(item.name, mList.length);
|
|
nextArtistCountMap.set(item.name, mList.length);
|
|
|
this.artistSongCountMap = nextArtistCountMap;
|
|
this.artistSongCountMap = nextArtistCountMap;
|
|
@@ -6701,7 +6800,7 @@ export struct LocalMusic {
|
|
|
if (item.pixelMapPath) {
|
|
if (item.pixelMapPath) {
|
|
|
this.currentTitleCover = item.pixelMapPath
|
|
this.currentTitleCover = item.pixelMapPath
|
|
|
}
|
|
}
|
|
|
- this.updateListData(mList)
|
|
|
|
|
|
|
+ this.updateListData(mList, true) // 使用 true 跳过排序
|
|
|
} else {
|
|
} else {
|
|
|
ToastUtil.showToast('未找到该艺术家的歌曲');
|
|
ToastUtil.showToast('未找到该艺术家的歌曲');
|
|
|
return;
|
|
return;
|
|
@@ -6751,15 +6850,32 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
this.mScrollMap.set('lastListAlBumScrollOffset', offset)
|
|
this.mScrollMap.set('lastListAlBumScrollOffset', offset)
|
|
|
}
|
|
}
|
|
|
- let albumList = this.albumMap.get(item.name)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 进入专辑详情页前,先加载详情页的排序类型
|
|
|
|
|
+ // 注意:需要临时设置isCanBack=true,以便loadSortTypeForCurrentMode读取详情页的排序设置
|
|
|
|
|
+ const albumOriginalIsCanBack = this.isCanBack;
|
|
|
|
|
+ this.isCanBack = true;
|
|
|
|
|
+ const albumDetailSortType = this.loadSortTypeForCurrentMode();
|
|
|
|
|
+ this.isCanBack = albumOriginalIsCanBack; // 恢复原值
|
|
|
|
|
+ Logger.info('heanup LocalMusic', `进入专辑详情页: 加载详情页排序 sortType=${albumDetailSortType}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 缓存键需要包含排序类型,因为不同的排序类型会产生不同的数据
|
|
|
|
|
+ const albumCacheKey = `${item.name}_sort_${albumDetailSortType}`;
|
|
|
|
|
+ let albumList = this.albumMap.get(albumCacheKey)
|
|
|
|
|
+
|
|
|
if (albumList === undefined || ArrayUtil.isEmpty(albumList)) {
|
|
if (albumList === undefined || ArrayUtil.isEmpty(albumList)) {
|
|
|
- albumList = await this.table.querySongsByAlbum(item.name, this.sortType, this.isShowFileName);
|
|
|
|
|
|
|
+ // 使用详情页的排序类型查询
|
|
|
|
|
+ albumList = await this.table.querySongsByAlbum(item.name, albumDetailSortType, this.isShowFileName);
|
|
|
if (ArrayUtil.isNotEmpty(albumList)) {
|
|
if (ArrayUtil.isNotEmpty(albumList)) {
|
|
|
- this.albumMap.set(item.name, albumList);
|
|
|
|
|
|
|
+ this.albumMap.set(albumCacheKey, albumList);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 设置当前排序类型为详情页排序
|
|
|
|
|
+ this.sortType = albumDetailSortType;
|
|
|
|
|
+
|
|
|
if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
|
|
if (albumList !== undefined && ArrayUtil.isNotEmpty(albumList)) {
|
|
|
- Utility.doSortListAscending(albumList)
|
|
|
|
|
|
|
+ // 注意:不再调用 Utility.doSortListAscending,因为数据已经按 albumDetailSortType 排序了
|
|
|
const nextAlbumCountMap = new Map(this.albumSongCountMap);
|
|
const nextAlbumCountMap = new Map(this.albumSongCountMap);
|
|
|
nextAlbumCountMap.set(item.name, albumList.length);
|
|
nextAlbumCountMap.set(item.name, albumList.length);
|
|
|
this.albumSongCountMap = nextAlbumCountMap;
|
|
this.albumSongCountMap = nextAlbumCountMap;
|
|
@@ -6773,7 +6889,7 @@ export struct LocalMusic {
|
|
|
if (item.pixelMapPath) {
|
|
if (item.pixelMapPath) {
|
|
|
this.currentTitleCover = item.pixelMapPath
|
|
this.currentTitleCover = item.pixelMapPath
|
|
|
}
|
|
}
|
|
|
- this.updateListData(albumList)
|
|
|
|
|
|
|
+ this.updateListData(albumList, true) // 使用 true 跳过排序
|
|
|
this.mScrollMap.set(item.name, this.selectedIndex)
|
|
this.mScrollMap.set(item.name, this.selectedIndex)
|
|
|
this.rightTopImage = $r('sys.symbol.chevron_left')
|
|
this.rightTopImage = $r('sys.symbol.chevron_left')
|
|
|
} else {
|
|
} else {
|