|
@@ -147,6 +147,10 @@ const ITEM_HEIGHT_BIG: number = 78; // 列表项大高度
|
|
|
@Preview
|
|
@Preview
|
|
|
@Component
|
|
@Component
|
|
|
export struct LocalMusic {
|
|
export struct LocalMusic {
|
|
|
|
|
+ @State isRefreshing: boolean = false;
|
|
|
|
|
+ @State maxRefreshingHeight: number = 100.0;
|
|
|
|
|
+ private contentNode?: ComponentContent<Object> = undefined;
|
|
|
|
|
+ @State ratioL: number = 1;
|
|
|
@State mediaKuCount: number = 0;
|
|
@State mediaKuCount: number = 0;
|
|
|
@State albumCount: number = 0;
|
|
@State albumCount: number = 0;
|
|
|
@State artistCount: number = 0;
|
|
@State artistCount: number = 0;
|
|
@@ -833,6 +837,7 @@ export struct LocalMusic {
|
|
|
this.doUpdateData()
|
|
this.doUpdateData()
|
|
|
break;
|
|
break;
|
|
|
case 102: //查询媒体库列表
|
|
case 102: //查询媒体库列表
|
|
|
|
|
+ this.isRefreshing = false
|
|
|
this.mediaKuList = e.data.data
|
|
this.mediaKuList = e.data.data
|
|
|
Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
|
|
Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
|
|
|
Utility.doSortListAscending(this.mediaKuList)
|
|
Utility.doSortListAscending(this.mediaKuList)
|
|
@@ -851,6 +856,7 @@ export struct LocalMusic {
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case 103: //收到查询艺术家列表
|
|
case 103: //收到查询艺术家列表
|
|
|
|
|
+ this.isRefreshing = false
|
|
|
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)
|
|
@@ -868,6 +874,7 @@ export struct LocalMusic {
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 104: //收到查询专辑列表
|
|
case 104: //收到查询专辑列表
|
|
|
|
|
+ this.isRefreshing = false
|
|
|
this.albumMap = e.data.data1;
|
|
this.albumMap = e.data.data1;
|
|
|
|
|
|
|
|
this.albumList = e.data.data2
|
|
this.albumList = e.data.data2
|
|
@@ -2191,7 +2198,22 @@ export struct LocalMusic {
|
|
|
if(this.isGridMusic){
|
|
if(this.isGridMusic){
|
|
|
this.getGridView()
|
|
this.getGridView()
|
|
|
}else {
|
|
}else {
|
|
|
- this.getListView()
|
|
|
|
|
|
|
+ Refresh({ refreshing: $$this.isRefreshing, refreshingContent: this.contentNode }) {
|
|
|
|
|
+ this.getListView()
|
|
|
|
|
+ }
|
|
|
|
|
+ .pullDownRatio(this.ratioL)
|
|
|
|
|
+ .pullToRefresh(true)
|
|
|
|
|
+ .refreshOffset(0)
|
|
|
|
|
+ .onOffsetChange((offset: number) => {
|
|
|
|
|
+ // 越接近最大距离,下拉跟手系数越小。
|
|
|
|
|
+ this.ratioL = 1 - Math.pow((offset / this.maxRefreshingHeight), 3);
|
|
|
|
|
+ })
|
|
|
|
|
+ .onStateChange((refreshStatus: RefreshStatus) => {
|
|
|
|
|
+ console.info('onecold Refresh onStatueChange state is ' + refreshStatus);
|
|
|
|
|
+ })
|
|
|
|
|
+ .onRefreshing(async () => {
|
|
|
|
|
+ this.refreshCurrent()
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (this.modeType == 0) {
|
|
if (this.modeType == 0) {
|
|
@@ -3237,6 +3259,19 @@ export struct LocalMusic {
|
|
|
return this.currentTitleCover
|
|
return this.currentTitleCover
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ refreshCurrent() {
|
|
|
|
|
+ if(this.modeType==0){
|
|
|
|
|
+ this.getHistoryList(false)
|
|
|
|
|
+ this.asyncCurrentPathOnlyFile()
|
|
|
|
|
+ }else if(this.modeType == 1){
|
|
|
|
|
+ workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
|
|
|
|
|
+ }else if(this.modeType == 2){
|
|
|
|
|
+ workerInstance.postMessage({ code: 3, data: this.context });
|
|
|
|
|
+ }else if(this.modeType == 3){
|
|
|
|
|
+ workerInstance.postMessage({ code: 4, data: this.context });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Builder
|
|
@Builder
|
|
|
listViewTitle() {
|
|
listViewTitle() {
|
|
|
Column() {
|
|
Column() {
|
|
@@ -3452,26 +3487,18 @@ export struct LocalMusic {
|
|
|
this.isSearchMode = true
|
|
this.isSearchMode = true
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- Image($r("app.media.refresh"))
|
|
|
|
|
- .fillColor(this.themeColor)
|
|
|
|
|
- .width(25)
|
|
|
|
|
- .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
|
|
|
|
|
- .animation({
|
|
|
|
|
- duration: 666,
|
|
|
|
|
- curve: 'ease-in-out' // 可选动画曲线
|
|
|
|
|
- })
|
|
|
|
|
- .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
|
|
|
|
|
- .onClick(() => {
|
|
|
|
|
- if (this.isFavMusic) {
|
|
|
|
|
- this.getFavList(true)
|
|
|
|
|
- } else {
|
|
|
|
|
- if(this.modeType == 0){
|
|
|
|
|
- this.asyncCurrentPathData()
|
|
|
|
|
- }else if(this.modeType ==1){
|
|
|
|
|
- workerInstance.postMessage({ code: 2, data: this.context,data2:this.packName });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ // Image($r("app.media.refresh"))
|
|
|
|
|
+ // .fillColor(this.themeColor)
|
|
|
|
|
+ // .width(25)
|
|
|
|
|
+ // .visibility(this.isHistory || this.isCanBack || this.isSearchMode ? Visibility.None : Visibility.Visible)
|
|
|
|
|
+ // .animation({
|
|
|
|
|
+ // duration: 666,
|
|
|
|
|
+ // curve: 'ease-in-out' // 可选动画曲线
|
|
|
|
|
+ // })
|
|
|
|
|
+ // .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
|
|
|
|
|
+ // .onClick(() => {
|
|
|
|
|
+ // this.refreshCurrent()
|
|
|
|
|
+ // })
|
|
|
|
|
|
|
|
Image($r("app.media.top_rank"))
|
|
Image($r("app.media.top_rank"))
|
|
|
.width(25)
|
|
.width(25)
|
|
@@ -4673,6 +4700,24 @@ export struct LocalMusic {
|
|
|
this.scaleValue = 1;
|
|
this.scaleValue = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 扫描当前目录下的文件,不扫描子目录
|
|
|
|
|
+ asyncCurrentPathOnlyFile(){
|
|
|
|
|
+ if(this.modeType==0){
|
|
|
|
|
+ const task = new taskpool.Task(scanCurrentDirectoryTask, getContext(this), this.currentPath,
|
|
|
|
|
+ this.lockPath,PreferencesUtil.getStringSync('COVER_API',''));
|
|
|
|
|
+ taskpool.execute(task, taskpool.Priority.HIGH).then(()=>{
|
|
|
|
|
+ if(this.modeType==0){
|
|
|
|
|
+ this.getSortedFiles(this.currentPath)
|
|
|
|
|
+ }
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.isRefreshing = false;
|
|
|
|
|
+ }, 100)
|
|
|
|
|
+ }).catch((e:object)=>{
|
|
|
|
|
+ console.info("task1 catch e: " + e);
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Builder
|
|
@Builder
|
|
|
getListView() {
|
|
getListView() {
|
|
|
|
|
|
|
@@ -13095,3 +13140,48 @@ function getFileDirName(filePath: string,rootPath:string): string{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+//只扫描当前目录下文件(不扫描子文件夹)的方法
|
|
|
|
|
+@Concurrent
|
|
|
|
|
+async function scanCurrentDirectoryTask(context: Context, dirPath: string, lockPath: string, cover_api: string) {
|
|
|
|
|
+ const table: MediaTable = new MediaTable(context);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 直接获取当前目录下的文件列表
|
|
|
|
|
+ const files = FileUtil.listFileSync(dirPath);
|
|
|
|
|
+
|
|
|
|
|
+ await Promise.all(files.map(async (file) => {
|
|
|
|
|
+ const fPath = `${dirPath}/${file}`;
|
|
|
|
|
+
|
|
|
|
|
+ // 跳过目录,只处理文件
|
|
|
|
|
+ if (FileUtil.isDirectory(fPath)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 跳过特定格式文件
|
|
|
|
|
+ if (fPath.endsWith('.lrc') || fPath.endsWith('.srt')) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否为媒体文件
|
|
|
|
|
+ if (Utility.isMeidaByExtension(fPath)) {
|
|
|
|
|
+ let mType = CommonConstants.TYPE_LOCAL;
|
|
|
|
|
+ if (fPath.includes(lockPath)) {
|
|
|
|
|
+ mType = CommonConstants.TYPE_LOCK;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const mediaItem = await Utility.uriGetMusicAssetsFromFile(
|
|
|
|
|
+ context, fPath, mType, true
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ table.insert(mediaItem, (id: number) => {
|
|
|
|
|
+ // 插入回调函数
|
|
|
|
|
+ }, cover_api);
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error(' 扫描当前目录失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|