Forráskód Böngészése

修复内嵌后刷新问题,下拉刷新问题

onecold 9 hónapja
szülő
commit
f01ac78bdd

+ 18 - 8
entry/src/main/ets/view/LocalMusic.ets

@@ -2523,11 +2523,11 @@ export struct LocalMusic {
                 transition: TransitionEffect.translate({ x: 500 }).animation({ curve: curves.springMotion(0.6, 0.8) })
               })
               .onClick(() => {
-                if(ArrayUtil.isNotEmpty(this.selectedFiles)&&Utility.isMerge(this.selectedFiles,this.packName)){
+                // if(ArrayUtil.isNotEmpty(this.selectedFiles)&&Utility.isMerge(this.selectedFiles,this.packName)){
                   this.isOneKeyTags = !this.isOneKeyTags
-                }else{
-                  ToastUtil.showToast('选中的文件包含了不是本应用的DownLoad文件下,其他路径音频无权限批量内嵌')
-                }
+                // }else{
+                //   ToastUtil.showToast('选中的文件包含了不是本应用的DownLoad文件下,其他路径音频无权限批量内嵌')
+                // }
 
               })
 
@@ -2665,10 +2665,13 @@ export struct LocalMusic {
           {
             selectedFiles:this.selectedFiles,
             isOneKeyTags:this.isOneKeyTags,
+            table:this.table,
             onTagsResult:(result: boolean)=>{
               this.isMultiSelect = false
               if(result){//如果嵌入成功,更新数据
-                this.doUpdateData()
+                setTimeout(()=>{
+                  this.doUpdateData()
+                },500)
               }
 
             }
@@ -2691,6 +2694,7 @@ export struct LocalMusic {
             onFixResult:(result: boolean)=>{
               this.isMultiSelect = false
               if(result){//如果嵌入成功,更新数据
+                this.deleteCache(this.currentPath)
                 this.doUpdateData()
               }
 
@@ -5495,10 +5499,16 @@ export struct LocalMusic {
         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
+            this.deleteCache(this.currentPath)
+            this.getSortedFiles(this.currentPath)
+          },500)
+
         }
       }).catch((e:object)=>{
-        console.info("task1 catch e: " + e);
+        this.isRefreshing =false
+        console.info("onecold task1 catch e: " + e);
       })
     }
   }
@@ -6554,7 +6564,7 @@ export struct LocalMusic {
     };
     let newInput = item.filePath
     //内嵌标签歌路径如果不是包含包名,输入newInput要赋值tempOutPath,然后tempOutPath为空
-    if(!item.filePath.toLowerCase().includes(this.packName)){
+    if(!item.filePath.toLowerCase().includes(this.packName)&&FileUtil.accessSync(tempOutPath)){
       newInput = tempOutPath
       tempOutPath  = ''
     }

+ 37 - 14
entry/src/main/ets/view/TagsContentCover.ets

@@ -2,7 +2,7 @@ import { common, ConfigurationConstant } from '@kit.AbilityKit';
 import { CommonConstants } from '../common/constants/CommonConstants';
 import { VideoItem } from '../viewmodel/VideoItem';
 import { LazyDataSource } from '../common/util/LazyDataSource';
-import { AppUtil, LogUtil, PreferencesUtil, StrUtil, ToastUtil } from '@pura/harmony-utils';
+import { AppUtil, FileUtil, LogUtil, PreferencesUtil, StrUtil, ToastUtil } from '@pura/harmony-utils';
 import fs from '@ohos.file.fs';
 import { changeMusicCover, findLocalCoverImage, getApiLyric, repairAudioMetadata,
   searchCover,
@@ -11,6 +11,8 @@ import { util } from '@kit.ArkTS';
 import { FFMpegTags, Utility } from '../common/util/Utility';
 import { DialogHelper } from '@pura/harmony-dialog';
 import PermissionUtil from '../common/util/PermissionUtil'
+import MediaTable from '../common/util/MediaTable';
+
 //批量编辑标签
 // 批量编辑标签
 @Component
@@ -22,6 +24,7 @@ export struct TagsContentCover {
   @State isCover:boolean = true
   @State download_path:string = ''
   @Link isOneKeyTags: boolean;
+  @Prop table: MediaTable
   @State packName: string = ''
   @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource([])
   @Prop selectedFiles: Array<VideoItem>
@@ -49,7 +52,10 @@ export struct TagsContentCover {
   }
 
   async aboutToAppear() {
-    this.download_path = PreferencesUtil.getStringSync('download_path')
+    this.download_path = PreferencesUtil.getStringSync('download_path')+'批量内嵌'+'/'
+    if (!FileUtil.accessSync(this.download_path)) {
+      FileUtil.mkdirSync(this.download_path)
+    }
     console.info('onecold download_path:', this.download_path)
     this.packName = AppUtil.getBundleName()
     // 确保 selectedFiles 有默认值后再初始化 dataSource
@@ -131,7 +137,24 @@ export struct TagsContentCover {
   @Builder
   TagSetting() {
     Column(){
+      Row() {
+        SymbolGlyph($r('sys.symbol.night_badge_clock'))
+          .fontSize(20)
+          .fontColor([this.themeColor])
+          .alignSelf(ItemAlign.Center)
+          .margin({ left: 15 })
+        Text('说明:不是本app路径下的歌曲将在DownLoad/天天静听/内嵌标签文件夹中生成新的内嵌歌曲。')
+          .margin({ left: 5 ,right: 5})
+          .fontSize(14)
+          .padding({top:4,bottom:4})
+          .fontColor($r('app.color.text_color'))
+          .fontWeight(480)
+          .layoutWeight(1)
 
+      }
+      .height(55)
+      .margin({top:15,bottom:8})
+      .clickEffect({level:ClickEffectLevel.HEAVY,scale:0.6})
       Row() {
         SymbolGlyph($r('sys.symbol.doc_text'))
           .fontSize(20)
@@ -321,7 +344,7 @@ export struct TagsContentCover {
       try {
         this.currentFileIndex = index + 1;
         this.currentFileName = item.name;
-
+        await PermissionUtil.activatePermission(item.filePath)
 
         let success = true;
         let tempOutPath = ''
@@ -348,10 +371,9 @@ export struct TagsContentCover {
           if (StrUtil.isNotEmpty(defaultCover)) {
             // 确保 filePath 存在
             if (item.filePath) {
-              await PermissionUtil.activatePermission(item.filePath)
               // 如果不是 packName 包下的文件,则直接路径用this.download_path
               if(!item.filePath.toLowerCase().includes(this.packName)){
-                tempOutPath  = item.parentPath+'/'+ item.fileName
+                tempOutPath  = this.download_path+ item.fileName
               }
               console.info('onecold tempOutPath: ' + tempOutPath)
 
@@ -417,7 +439,7 @@ export struct TagsContentCover {
             const metadata: FFMpegTags = {};
             let newInput = item.filePath
             //内嵌标签歌路径如果不是包含包名,输入newInput要赋值tempOutPath,然后tempOutPath为空
-            if(!item.filePath.toLowerCase().includes(this.packName)){
+            if(!item.filePath.toLowerCase().includes(this.packName)&&FileUtil.accessSync(tempOutPath)){
               newInput = tempOutPath
               tempOutPath  = ''
             }
@@ -432,14 +454,15 @@ export struct TagsContentCover {
             if (!result) {
               success = false;
             }else{
-              // if(!item.filePath.includes(this.packName)){
-              //   //内嵌成功的歌路径如果不是包含包名,则要入库
-              //   let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newInput,
-              //     CommonConstants.TYPE_LOCAL, true);
-              //   this.table.insert(newItem, (id: number) => {
-              //
-              //   });
-              // }
+              if(!item.filePath.includes(this.packName)){
+                //内嵌成功的歌路径如果不是包含包名,则要入库
+                let newItem: VideoItem = await Utility.uriGetMusicAssetsFromFile(this.context, newInput,
+                  CommonConstants.TYPE_LOCAL, true);
+                this.table.insert(newItem, (id: number) => {
+
+
+                });
+              }
               //内嵌成功后同步歌词到数据库
               syncLyricToDB(this.context,item.filePath,lyricContent)
             }