|
@@ -145,6 +145,9 @@ const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
|
|
|
@Preview
|
|
@Preview
|
|
|
@Component
|
|
@Component
|
|
|
export struct LocalMusic {
|
|
export struct LocalMusic {
|
|
|
|
|
+ @State mediaKuCount: number = 0;
|
|
|
|
|
+ @State albumCount: number = 0;
|
|
|
|
|
+ @State artistCount: number = 0;
|
|
|
@State fastForwardSeconds: string = '10'
|
|
@State fastForwardSeconds: string = '10'
|
|
|
@State isShowBackFast: boolean = true//快进快退按钮
|
|
@State isShowBackFast: boolean = true//快进快退按钮
|
|
|
@State isCanAuto:boolean = true
|
|
@State isCanAuto:boolean = true
|
|
@@ -505,16 +508,9 @@ export struct LocalMusic {
|
|
|
this.appName = appName
|
|
this.appName = appName
|
|
|
})
|
|
})
|
|
|
this.packName = AppUtil.getBundleName()
|
|
this.packName = AppUtil.getBundleName()
|
|
|
- this.loadCacheFromStorage(); // 加载缓存
|
|
|
|
|
- // 在首页初始化时读取媒体库缓存数据
|
|
|
|
|
- let cachedListStr:string = PreferencesUtil.getStringSync('mediaKuList', '[]');
|
|
|
|
|
- let cachedList = JSON.parse(cachedListStr) as Array<VideoItem>;
|
|
|
|
|
- if(ArrayUtil.isNotEmpty(cachedList)){
|
|
|
|
|
- this.mediaKuList = cachedList
|
|
|
|
|
- if(this.modeType==1){
|
|
|
|
|
- this.updateListData(this.mediaKuList)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.loadCacheFromStorage(); // 加载文件夹缓存
|
|
|
|
|
+ // 在首页初始化时读取媒体库,艺术家,专辑等缓存数据
|
|
|
|
|
+ this.initLoadCache()
|
|
|
|
|
|
|
|
this.mkDownLoadDir()
|
|
this.mkDownLoadDir()
|
|
|
|
|
|
|
@@ -628,6 +624,45 @@ export struct LocalMusic {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //载入媒体库,艺术家,专辑等缓存
|
|
|
|
|
+ initLoadCache(){
|
|
|
|
|
+ this.mediaKuCount = PreferencesUtil.getNumberSync('mediaKuCount', 0)
|
|
|
|
|
+ this.artistCount = PreferencesUtil.getNumberSync('artistCount', 0)
|
|
|
|
|
+ this.albumCount = PreferencesUtil.getNumberSync('albumCount', 0)
|
|
|
|
|
+ let cachedListStr:string = PreferencesUtil.getStringSync('mediaKuList', '[]');
|
|
|
|
|
+ let cachedList = JSON.parse(cachedListStr) as Array<VideoItem>;
|
|
|
|
|
+ if(ArrayUtil.isNotEmpty(cachedList)){
|
|
|
|
|
+ this.mediaKuList = cachedList
|
|
|
|
|
+ if(this.modeType==1){
|
|
|
|
|
+ this.updateListData(this.mediaKuList)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let artistListStr:string = PreferencesUtil.getStringSync('artistList', '[]');
|
|
|
|
|
+ let artistCachedList = JSON.parse(artistListStr) as Array<VideoItem>;
|
|
|
|
|
+ if(ArrayUtil.isNotEmpty(artistCachedList)){
|
|
|
|
|
+ this.artistList = artistCachedList
|
|
|
|
|
+ let artistMapStr:string = PreferencesUtil.getStringSync('artistMap', '[]');
|
|
|
|
|
+ const parsedArray = JSON.parse(artistMapStr) as [string, VideoItem[]][];
|
|
|
|
|
+ this.artistMap = new Map(parsedArray);
|
|
|
|
|
+ // this.artistMap = JSON.parse(artistMapStr) as Map<string, VideoItem[]>;
|
|
|
|
|
+ if(this.modeType==2){
|
|
|
|
|
+ this.updateListData(this.artistList)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let albumListStr:string = PreferencesUtil.getStringSync('albumList', '[]');
|
|
|
|
|
+ let albumCachedList = JSON.parse(albumListStr) as Array<VideoItem>;
|
|
|
|
|
+ if(ArrayUtil.isNotEmpty(albumCachedList)){
|
|
|
|
|
+ this.albumList = albumCachedList
|
|
|
|
|
+ let albumMapStr:string = PreferencesUtil.getStringSync('albumMap', '[]');
|
|
|
|
|
+ const parsedArray = JSON.parse(albumMapStr) as [string, VideoItem[]][];
|
|
|
|
|
+ this.albumMap = new Map(parsedArray);
|
|
|
|
|
+ if(this.modeType==3){
|
|
|
|
|
+ this.updateListData(this.albumList)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
startAutoHide() {
|
|
startAutoHide() {
|
|
|
if(this.isHiCar()){
|
|
if(this.isHiCar()){
|
|
|
return
|
|
return
|
|
@@ -798,10 +833,10 @@ export struct LocalMusic {
|
|
|
this.updateListData(this.mediaKuList)
|
|
this.updateListData(this.mediaKuList)
|
|
|
}
|
|
}
|
|
|
PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
|
|
PreferencesUtil.putSync('mediaKuCount', this.mediaKuList.length)
|
|
|
- // 处理媒体库前50条记录,列表长度并存储到PreferencesUtil
|
|
|
|
|
- if (ArrayUtil.isNotEmpty(this.mediaKuList)&&this.mediaKuList.length > 50) {
|
|
|
|
|
- // 只保存前50条记录到缓存中
|
|
|
|
|
- let truncatedList = this.mediaKuList.slice(0, 50);
|
|
|
|
|
|
|
+ // 处理媒体库前100条记录,列表长度并存储到PreferencesUtil
|
|
|
|
|
+ if (ArrayUtil.isNotEmpty(this.mediaKuList)&&this.mediaKuList.length > 100) {
|
|
|
|
|
+ // 只保存前100条记录到缓存中
|
|
|
|
|
+ let truncatedList = this.mediaKuList.slice(0, 100);
|
|
|
PreferencesUtil.putSync('mediaKuList', JSON.stringify(truncatedList));
|
|
PreferencesUtil.putSync('mediaKuList', JSON.stringify(truncatedList));
|
|
|
} else {
|
|
} else {
|
|
|
PreferencesUtil.putSync('mediaKuList', JSON.stringify(this.mediaKuList));
|
|
PreferencesUtil.putSync('mediaKuList', JSON.stringify(this.mediaKuList));
|
|
@@ -811,6 +846,17 @@ export struct LocalMusic {
|
|
|
this.artistMap = e.data.data1;
|
|
this.artistMap = e.data.data1;
|
|
|
this.artistList = e.data.data2;
|
|
this.artistList = e.data.data2;
|
|
|
PreferencesUtil.putSync('artistCount', this.artistList.length)
|
|
PreferencesUtil.putSync('artistCount', this.artistList.length)
|
|
|
|
|
+
|
|
|
|
|
+ // 处理艺术家前100条记录,列表长度并存储到PreferencesUtil
|
|
|
|
|
+ if (ArrayUtil.isNotEmpty(this.artistList)&&this.artistList.length > 100) {
|
|
|
|
|
+ // 只保存前100条记录到缓存中
|
|
|
|
|
+ let truncatedList = this.artistList.slice(0, 100);
|
|
|
|
|
+ PreferencesUtil.putSync('artistList', JSON.stringify(truncatedList));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ PreferencesUtil.putSync('artistList', JSON.stringify(this.artistList));
|
|
|
|
|
+ }
|
|
|
|
|
+ const mapArray = Array.from(this.artistMap.entries());
|
|
|
|
|
+ PreferencesUtil.putSync('artistMap', JSON.stringify(mapArray));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 104: //收到查询专辑列表
|
|
case 104: //收到查询专辑列表
|
|
@@ -824,6 +870,16 @@ export struct LocalMusic {
|
|
|
this.startPlayOrResumePlay()
|
|
this.startPlayOrResumePlay()
|
|
|
}
|
|
}
|
|
|
PreferencesUtil.putSync('albumCount', this.albumList.length)
|
|
PreferencesUtil.putSync('albumCount', this.albumList.length)
|
|
|
|
|
+ // 处理专辑前100条记录,列表长度并存储到PreferencesUtil
|
|
|
|
|
+ if (ArrayUtil.isNotEmpty(this.albumList)&&this.albumList.length > 100) {
|
|
|
|
|
+ // 只保存前100条记录到缓存中
|
|
|
|
|
+ let truncatedList = this.albumList.slice(0, 100);
|
|
|
|
|
+ PreferencesUtil.putSync('albumList', JSON.stringify(truncatedList));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ PreferencesUtil.putSync('albumList', JSON.stringify(this.albumList));
|
|
|
|
|
+ }
|
|
|
|
|
+ const mapArrayAlbum = Array.from(this.albumMap.entries());
|
|
|
|
|
+ PreferencesUtil.putSync('albumMap', JSON.stringify(mapArrayAlbum));
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -3146,12 +3202,14 @@ export struct LocalMusic {
|
|
|
.margin({ left: 8 })
|
|
.margin({ left: 8 })
|
|
|
.fillColor(this.themeColor)
|
|
.fillColor(this.themeColor)
|
|
|
|
|
|
|
|
- Text(`共找到${this.artistList.length}位艺术家`)
|
|
|
|
|
|
|
+ Text(this.artistList.length ==100 ? `共找到${this.artistCount}位艺术家`
|
|
|
|
|
+ :`共找到${this.artistList.length}位艺术家`)
|
|
|
.fontColor($r('app.color.text_color'))
|
|
.fontColor($r('app.color.text_color'))
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.opacity(this.opacityItem)
|
|
.opacity(this.opacityItem)
|
|
|
.visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
|
|
.visibility(this.modeType === 2 ? Visibility.Visible : Visibility.None)
|
|
|
- Text(`共找到${this.albumList.length}张专辑`)
|
|
|
|
|
|
|
+ Text(this.albumList.length ==100 ? `共找到${this.albumCount+''}张专辑`
|
|
|
|
|
+ :`共找到${this.albumList.length}张专辑`)
|
|
|
.fontColor($r('app.color.text_color'))
|
|
.fontColor($r('app.color.text_color'))
|
|
|
.opacity(this.opacityItem)
|
|
.opacity(this.opacityItem)
|
|
|
.visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
|
|
.visibility(this.modeType === 3 ? Visibility.Visible : Visibility.None)
|
|
@@ -3256,7 +3314,9 @@ export struct LocalMusic {
|
|
|
curve: 'ease-in-out' // 可选动画曲线
|
|
curve: 'ease-in-out' // 可选动画曲线
|
|
|
})
|
|
})
|
|
|
if(Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length>0){
|
|
if(Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length>0){
|
|
|
- Text(`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
|
|
|
|
|
|
|
+ Text(this.modeType==1&&Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length==100?
|
|
|
|
|
+ `(${this.mediaKuCount}首)`
|
|
|
|
|
+ :`(${Utility.getGlobalList(this.videoLocalList, CommonConstants.TYPE_LOCAL).length}首)`)
|
|
|
.fontColor($r('app.color.text_color'))
|
|
.fontColor($r('app.color.text_color'))
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
|
.opacity(this.opacityItem)
|
|
.opacity(this.opacityItem)
|