|
|
@@ -452,6 +452,7 @@ export struct LocalMusic {
|
|
|
private pageCache: Map<number, VideoItem[]> = new Map() // 页面缓存(最多保留3页)
|
|
|
private prefetchingPages: Set<number> = new Set()
|
|
|
private playQueueScope: 'view' | 'history' | 'fav' | 'playlist' | 'single' = 'view'
|
|
|
+ private isHydratingPlayList: boolean = false
|
|
|
@StorageProp('isLandscape') @Watch('onIsLandscapeChange') isLandscape: boolean = false;
|
|
|
@StorageProp('topSafeHeight') topSafeHeight: number = 0;
|
|
|
@StorageProp('bottomSafeHeight') bottomSafeHeight: number = 0;
|
|
|
@@ -1704,6 +1705,7 @@ export struct LocalMusic {
|
|
|
//穿山甲
|
|
|
// this.loadBannerAd(CSJUtil.getBannerID())
|
|
|
|
|
|
+ this.restoreLastPlayContext();
|
|
|
this.songList = PreferencesUtil.getSync('LastMusicList', []) as Array<VideoItem>
|
|
|
this.currentSong = PreferencesUtil.getSync('LastMusicInfo', undefined) as VideoItem
|
|
|
if (ArrayUtil.isEmpty(this.songList)) {
|
|
|
@@ -2045,6 +2047,77 @@ export struct LocalMusic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private getPlayListDisplayCount(): number {
|
|
|
+ if (this.playQueueScope === 'history') {
|
|
|
+ return this.historyList.length;
|
|
|
+ }
|
|
|
+ if (this.playQueueScope === 'fav') {
|
|
|
+ return this.favList.length;
|
|
|
+ }
|
|
|
+ if (this.playQueueScope === 'playlist') {
|
|
|
+ return this.currentSongList.length;
|
|
|
+ }
|
|
|
+ if (this.playQueueScope === 'view' && this.modeType === 1 && this.totalCount > 0) {
|
|
|
+ return this.totalCount;
|
|
|
+ }
|
|
|
+ return this.songList.length;
|
|
|
+ }
|
|
|
+
|
|
|
+ private restoreLastPlayContext(): void {
|
|
|
+ const scope = PreferencesUtil.getStringSync('LastPlayQueueScope', 'view') as string;
|
|
|
+ if (scope === 'history' || scope === 'fav' || scope === 'playlist' || scope === 'single') {
|
|
|
+ this.playQueueScope = scope;
|
|
|
+ } else {
|
|
|
+ this.playQueueScope = 'view';
|
|
|
+ }
|
|
|
+ const lastModeType = PreferencesUtil.getNumberSync('LastPlayModeType', this.modeType);
|
|
|
+ const lastTotalCount = PreferencesUtil.getNumberSync('LastPlayTotalCount', 0);
|
|
|
+ if (lastModeType === 1 && this.totalCount === 0 && lastTotalCount > 0) {
|
|
|
+ this.totalCount = lastTotalCount;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async hydrateFullMediaPlayListIfNeeded(): Promise<void> {
|
|
|
+ if (this.isHydratingPlayList) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.playQueueScope !== 'view' || this.modeType !== 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.totalCount === 0 || this.songList.length >= this.totalCount) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.isHydratingPlayList = true;
|
|
|
+ try {
|
|
|
+ const fullList: VideoItem[] = [];
|
|
|
+ let pageIndex = 0;
|
|
|
+ let hasMore = true;
|
|
|
+ while (hasMore) {
|
|
|
+ const result = await this.table.queryMediaLibraryPaged({
|
|
|
+ pageIndex,
|
|
|
+ pageSize: this.pageSize,
|
|
|
+ sortType: this.sortType,
|
|
|
+ searchKeyword: this.isSearchMode ? this.searchText : undefined
|
|
|
+ });
|
|
|
+ if (result.items.length === 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ fullList.push(...result.items);
|
|
|
+ hasMore = result.hasMore;
|
|
|
+ pageIndex += 1;
|
|
|
+ if (fullList.length >= result.totalCount) {
|
|
|
+ hasMore = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (fullList.length > 0) {
|
|
|
+ this.songList = fullList;
|
|
|
+ this.sonDataSource.pushArrayData(this.songList);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ this.isHydratingPlayList = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Builder
|
|
|
SortMenuBuilder() {
|
|
|
@@ -2792,7 +2865,7 @@ export struct LocalMusic {
|
|
|
backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
|
|
|
title: {
|
|
|
title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
|
|
|
- + `(${this.songList.length}首)`
|
|
|
+ + `(${this.getPlayListDisplayCount()}首)`
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -6784,6 +6857,7 @@ export struct LocalMusic {
|
|
|
LogUtil.info('onecold scrollToIndex = ' + this.curIndex)
|
|
|
|
|
|
this.scrollIndex()
|
|
|
+ void this.hydrateFullMediaPlayListIfNeeded();
|
|
|
|
|
|
} else {
|
|
|
ToastUtil.showToast('当前播放列表为空,请先导入音乐。')
|
|
|
@@ -8891,6 +8965,9 @@ export struct LocalMusic {
|
|
|
}
|
|
|
.width('100%')
|
|
|
.height('100%')
|
|
|
+ .onReachEnd(() => {
|
|
|
+ void this.tryLoadNextPageForPlayback();
|
|
|
+ })
|
|
|
// .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
|
|
|
// .animation({ duration: 500, curve: Curve.Ease }))
|
|
|
.cachedCount(10)
|
|
|
@@ -10551,7 +10628,7 @@ export struct LocalMusic {
|
|
|
backgroundColor: this.isPlayListBgGrass?Color.Transparent:$r('app.color.silvery'),
|
|
|
title: {
|
|
|
title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
|
|
|
- + `(${this.songList.length}首)`
|
|
|
+ + `(${this.getPlayListDisplayCount()}首)`
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -10567,6 +10644,7 @@ export struct LocalMusic {
|
|
|
this.isFrontWhite = false
|
|
|
}
|
|
|
this.scrollIndex()
|
|
|
+ void this.hydrateFullMediaPlayListIfNeeded();
|
|
|
})
|
|
|
|
|
|
}
|
|
|
@@ -10698,7 +10776,7 @@ export struct LocalMusic {
|
|
|
backgroundColor: this.isPlayListBgGrass ? Color.Transparent : $r('app.color.silvery'),
|
|
|
title: {
|
|
|
title: Utility.resourceToString(this.context, $r('app.string.current_play_list'))
|
|
|
- + `(${this.songList.length}首)`
|
|
|
+ + `(${this.getPlayListDisplayCount()}首)`
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -10718,6 +10796,7 @@ export struct LocalMusic {
|
|
|
this.isFrontWhite = false
|
|
|
}
|
|
|
this.scrollIndex()
|
|
|
+ void this.hydrateFullMediaPlayListIfNeeded();
|
|
|
})
|
|
|
|
|
|
}
|
|
|
@@ -13808,6 +13887,9 @@ export struct LocalMusic {
|
|
|
saveLastPlayList() {
|
|
|
PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
|
|
|
PreferencesUtil.putSync('LastMusicList', this.songList)
|
|
|
+ PreferencesUtil.putSync('LastPlayQueueScope', this.playQueueScope)
|
|
|
+ PreferencesUtil.putSync('LastPlayModeType', this.modeType)
|
|
|
+ PreferencesUtil.putSync('LastPlayTotalCount', this.totalCount)
|
|
|
|
|
|
}
|
|
|
|