|
|
@@ -163,7 +163,7 @@ const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
|
|
|
@Preview
|
|
|
@Component
|
|
|
export struct LocalMusic {
|
|
|
- @Consume currentSongList: Array<VideoItem>//当前歌单
|
|
|
+ @State currentSongList: Array<VideoItem> = []//当前歌单
|
|
|
@Consume currentSongListName:string //当前歌单名称
|
|
|
@Consume @Watch('onIDChange') currentSongListID:string //当前歌单ID
|
|
|
@State isRefreshing: boolean = false;
|
|
|
@@ -301,15 +301,23 @@ export struct LocalMusic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //歌单id发生变化的时候回调
|
|
|
+ //点击某个歌单id发生变化的时候回调
|
|
|
onIDChange(){
|
|
|
+ console.log('onecold 歌单id发生变化this.currentSongListID='+this.currentSongListID)
|
|
|
+ console.log('onecold 歌单id发生变化this.currentSongListName='+this.currentSongListName)
|
|
|
if(this.modeType==4){
|
|
|
-
|
|
|
- this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
|
|
|
- this.updateListData(this.currentSongList, true)
|
|
|
this.titleBarModel.setTitleName(this.currentSongListName)
|
|
|
- this.isShowTitleBar = false
|
|
|
- console.log('歌单id发生变化')
|
|
|
+ this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
|
|
|
+ console.log('onecold 歌单id发生变化获取缓存1')
|
|
|
+ //获取缓存
|
|
|
+ const cacheSongs:string =PreferencesUtil.getStringSync(this.currentSongListID+'currentSongList', '')
|
|
|
+ console.log('onecold 歌单id发生变化获取缓存2 cacheSongs = '+cacheSongs)
|
|
|
+ if(StrUtil.isNotEmpty(cacheSongs)){
|
|
|
+ this.currentSongList = JSON.parse(cacheSongs) as VideoItem[]
|
|
|
+ console.log('onecold 歌单id发生变化获取缓存3 this.currentSongList = '+this.currentSongList.length)
|
|
|
+ this.updateListData(this.currentSongList, true)
|
|
|
+ this.isShowTitleBar = false
|
|
|
+ }
|
|
|
this.doSongListTask()//获取歌单信息
|
|
|
}
|
|
|
|
|
|
@@ -318,13 +326,29 @@ export struct LocalMusic {
|
|
|
async doSongListTask() {
|
|
|
// 初始化歌单数据库
|
|
|
const playlistTable = new PlaylistTable(this.context);
|
|
|
+ console.log('onecold 歌单id发生变化获取缓存6')
|
|
|
// 查询歌单中的所有歌曲
|
|
|
const playlistSongs: PlaylistSong[] = await playlistTable.queryPlaylistSongs(this.currentSongListID);
|
|
|
+ console.log('onecold 歌单id发生变化获取缓存7 playlistSongs='+playlistSongs.length)
|
|
|
if (ArrayUtil.isEmpty(playlistSongs)) {
|
|
|
- ToastUtil.showToast('当前歌单为空')
|
|
|
+ ToastUtil.showToast('当前歌单为空')
|
|
|
+ this.updateListData([], true)
|
|
|
} else {
|
|
|
this.currentSongList = await convertPlaylistSongsToVideoItems(this.context, playlistSongs);
|
|
|
+ console.log('onecold 从数据库读取的歌曲为 playlistSongs='+JSON.stringify(this.currentSongList))
|
|
|
+ console.log('onecold 从数据库读取的歌曲为 playlistSongs='+this.currentSongList.length)
|
|
|
this.updateListData(this.currentSongList, true)
|
|
|
+
|
|
|
+ if (ArrayUtil.isNotEmpty(this.currentSongList)&&this.currentSongList.length > 100) {
|
|
|
+ // 只保存前100条记录到缓存中
|
|
|
+ let canceList = this.currentSongList.slice(0, 100);
|
|
|
+ PreferencesUtil.putSync(this.currentSongListID+'currentSongList',
|
|
|
+ JSON.stringify(canceList))
|
|
|
+ } else {
|
|
|
+ PreferencesUtil.putSync(this.currentSongListID+'currentSongList', JSON.stringify(this.currentSongList));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -357,13 +381,6 @@ export struct LocalMusic {
|
|
|
this.updateListData(this.albumList)
|
|
|
this.titleBarModel.setTitleName(Utility.resourceToString(this.context, $r('app.string.album')))
|
|
|
break
|
|
|
- case 4://歌单
|
|
|
- this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
|
|
|
- this.updateListData(this.currentSongList, true)
|
|
|
- this.titleBarModel.setTitleName(this.currentSongListName)
|
|
|
- this.isShowTitleBar = false
|
|
|
- this.doSongListTask()//获取歌单信息
|
|
|
- break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -3580,6 +3597,8 @@ export struct LocalMusic {
|
|
|
this.updateListData(this.artistList)
|
|
|
} else if(this.modeType==3&&!this.isCanBack){
|
|
|
this.updateListData(this.albumList)
|
|
|
+ }else if(this.modeType==4){
|
|
|
+ this.doSongListTask()
|
|
|
}
|
|
|
|
|
|
})
|
|
|
@@ -3608,7 +3627,7 @@ export struct LocalMusic {
|
|
|
Image($r("app.media.refresh"))
|
|
|
.fillColor(this.themeColor)
|
|
|
.width(25)
|
|
|
- .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
|
|
|
+ .visibility(this.modeType ==4||this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
|
|
|
.animation({
|
|
|
duration: 666,
|
|
|
curve: 'ease-in-out' // 可选动画曲线
|
|
|
@@ -4834,6 +4853,8 @@ export struct LocalMusic {
|
|
|
workerInstance.postMessage({ code: 3, data: this.context });
|
|
|
}else if(this.modeType == 3){
|
|
|
workerInstance.postMessage({ code: 4, data: this.context });
|
|
|
+ }else if(this.modeType == 4){
|
|
|
+ this.doSongListTask()
|
|
|
}
|
|
|
|
|
|
|