Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

onecold před 9 měsíci
rodič
revize
db252d62f2
1 změnil soubory, kde provedl 117 přidání a 17 odebrání
  1. 117 17
      entry/src/main/ets/view/LocalMusic.ets

+ 117 - 17
entry/src/main/ets/view/LocalMusic.ets

@@ -312,6 +312,7 @@ export struct LocalMusic {
   @State dirList: Array<VideoItem> = []
   @Consume videoLocalList:VideoItem[]
   @State dataSource: LazyDataSource<VideoItem> = new LazyDataSource(this.videoLocalList)
+  @State listRefreshKey: number = 0
   // @State mediaKuList: Array<VideoItem> = []; //媒体库文件
   @StorageProp('mediaKuList')  mediaKuList: Array<VideoItem> = []; //媒体库文件
   @State artistList: Array<VideoItem> = []; //艺术家文件
@@ -4311,7 +4312,7 @@ export struct LocalMusic {
                   })
               )
             )
-          }, (item: VideoItem) =>  item.filePath)
+          }, (item: VideoItem) =>  item.filePath + '_' + this.listRefreshKey)
         }
         // .columnsTemplate('repeat(auto-fit, 160)')
         .id('waterflow') // 设置id用于截图
@@ -4749,7 +4750,7 @@ export struct LocalMusic {
         .translate(this.dragItem === index ? { x: this.offsetX, y: this.offsetY } : { x: 0, y: 0 })
 
 
-      }, (item: VideoItem) => item.filePath)
+      }, (item: VideoItem) => item.filePath + '_' + this.listRefreshKey)
     }
     .width('94%')
     .height('100%')
@@ -5120,7 +5121,7 @@ export struct LocalMusic {
               .onClick(async () => {
                 this.longItemFilePath = ''
                 await this.openAddToPlaylistDialog(item)
-              })
+            })
 
             MenuItem({
               symbolStartIcon: new SymbolGlyphModifier($r('sys.symbol.square_and_pencil')),
@@ -5135,8 +5136,11 @@ export struct LocalMusic {
               })
               .visibility(item.type === CommonConstants.TYPE_IS_DIR ? Visibility.None : Visibility.Visible)
               .onClick(async() => {
-                this.setEditStrEmpty()
+                this.initEditFields(item)
                 this.tempLyricContent = await this.getLyricContent(item);
+                if (StrUtil.isNotEmpty(this.tempLyricContent)) {
+                  this.lyricConStr = this.tempLyricContent
+                }
                 if(this.isGridMusic||this.twoFingerType==4){
                   this.longItemFilePath = item.filePath
                 }else{
@@ -5542,7 +5546,7 @@ export struct LocalMusic {
               })
           ) //拖动List关键代码结束
 
-        }, (item: VideoItem) => item.filePath)
+        }, (item: VideoItem) => item.filePath + '_' + this.listRefreshKey)
       // }
     }
     .scrollBar(BarState.Off)
@@ -6509,6 +6513,7 @@ export struct LocalMusic {
           ToastUtil.showToast('内嵌音乐标签成功')
           this.isShowMoreView = false
           this.name = this.titleStr
+          this.syncEditedFields(item)
           if (item.filePath == this.currentSong?.filePath) {
             this.currentSong.name = this.titleStr
             this.artist = this.artistStr
@@ -6526,6 +6531,7 @@ export struct LocalMusic {
             this.currentSong.COMMENT = this.commentStr
           }
 
+          this.syncListsAfterEdit(item.filePath)
           this.doUpdateData()
         } else {
           // ToastUtil.showToast('保存失败' + error?.toString())
@@ -7118,6 +7124,91 @@ export struct LocalMusic {
     this.discStr = ''
   }
 
+  initEditFields(item?: VideoItem) {
+    if (!item) {
+      this.setEditStrEmpty()
+      return
+    }
+    this.imagePathStr = ''
+    this.titleStr = item.name ?? ''
+    this.artistStr = item.artist ?? ''
+    this.ablumStr = item.album ?? ''
+    this.genreStr = item.genre ?? ''
+    this.yearStr = item.year ?? ''
+    this.trackStr = item.track ?? ''
+    this.albumArtistStr = item.ALBUMARTIST ?? ''
+    this.composerStr = item.COMPOSER ?? ''
+    this.lyricistStr = item.LYRICIST ?? ''
+    this.commentStr = item.COMMENT ?? ''
+    this.discStr = item.disc ?? ''
+    this.lyricConStr = item.lyricContent ?? ''
+  }
+
+  private syncEditedFields(target?: VideoItem) {
+    if (!target) {
+      return
+    }
+    target.name = this.titleStr
+    target.artist = this.artistStr
+    target.album = this.ablumStr
+    target.lyricContent = this.lyricConStr
+    target.year = this.yearStr
+    target.genre = this.genreStr
+    target.track = this.trackStr
+    target.ALBUMARTIST = this.albumArtistStr
+    target.COMPOSER = this.composerStr
+    target.LYRICIST = this.lyricistStr
+    target.COMMENT = this.commentStr
+    target.disc = this.discStr
+  }
+
+  private replaceItemInList(list: Array<VideoItem> | undefined, filePath: string,
+    apply?: (next: Array<VideoItem>) => void) {
+    if (!list || ArrayUtil.isEmpty(list)) {
+      return
+    }
+    const index = list.findIndex((video: VideoItem) => video.filePath === filePath)
+    if (index < 0) {
+      return
+    }
+    const nextList = [...list]
+    this.syncEditedFields(nextList[index])
+    apply?.(nextList)
+  }
+
+  private syncListsAfterEdit(filePath: string) {
+    this.replaceItemInList(this.videoLocalList, filePath, (next: Array<VideoItem>) => {
+      this.videoLocalList = next
+      this.dataSource.pushArrayData(next)
+    })
+    this.replaceItemInList(this.songList, filePath, (next: Array<VideoItem>) => {
+      this.songList = next
+      this.sonDataSource.pushArrayData(next)
+    })
+    this.replaceItemInList(this.favList, filePath, (next: Array<VideoItem>) => {
+      this.favList = next
+    })
+    this.replaceItemInList(this.historyList, filePath, (next: Array<VideoItem>) => {
+      this.historyList = next
+    })
+    this.replaceItemInList(this.currentSongList, filePath, (next: Array<VideoItem>) => {
+      this.currentSongList = next
+    })
+    this.replaceItemInList(this.mediaKuList, filePath, (next: Array<VideoItem>) => {
+      this.mediaKuList = next
+    })
+    this.replaceItemInList(this.filteredList, filePath, (next: Array<VideoItem>) => {
+      this.filteredList = next
+    })
+    this.replaceItemInList(this.artistList, filePath, (next: Array<VideoItem>) => {
+      this.artistList = next
+    })
+    this.replaceItemInList(this.albumList, filePath, (next: Array<VideoItem>) => {
+      this.albumList = next
+    })
+    this.listRefreshKey++
+  }
+
   @Builder
   detailSheet(item:VideoItem) {
     Scroll() {
@@ -7979,7 +8070,7 @@ export struct LocalMusic {
         .onClick(() => {
           this.doPlay(item, index, true)
         })
-      }, (item: VideoItem) => item.filePath)
+      }, (item: VideoItem) => item.filePath + '_' + this.listRefreshKey)
     }
     .width('100%')
     .height('100%')
@@ -9520,8 +9611,11 @@ export struct LocalMusic {
         .layoutWeight(1)
         .backgroundColor(Color.Transparent)
         .onClick(async () => {
-          this.setEditStrEmpty()
+          this.initEditFields(this.currentSong)
           this.tempLyricContent = this.lyricContent
+          if (StrUtil.isNotEmpty(this.tempLyricContent)) {
+            this.lyricConStr = this.tempLyricContent
+          }
           this.isShowEdit = !this.isShowEdit;
         })
       }
@@ -11546,8 +11640,11 @@ export struct LocalMusic {
         this.isShowMoreView = false
         break;
       case 15: //编辑标签
-        this.setEditStrEmpty()
+        this.initEditFields(this.currentSong)
         this.tempLyricContent = this.lyricContent
+        if (StrUtil.isNotEmpty(this.tempLyricContent)) {
+          this.lyricConStr = this.tempLyricContent
+        }
         this.isShowEdit = !this.isShowEdit;
         break;
       case 16: //悬浮歌词
@@ -14324,13 +14421,16 @@ async function updateInfoDb(
     });
   });
 
-  return table.updateMediaInfo(filePath, titleStr, artistStr, albumStr, lyricConStr,
-    yearStr, genreStr, trackStr, albumArtistStr, composerStr, lyricistStr, commentStr, discStr,
-    (success: boolean, error?: string) => {
-      if (success) {
-        console.log("onecold 编辑信息成功,数据库已同步");
-      } else {
-        console.error("onecold 编辑信息数据库失败原因: " + error);
-      }
-    });
+  return await new Promise<boolean>((resolve) => {
+    table.updateMediaInfo(filePath, titleStr, artistStr, albumStr, lyricConStr,
+      yearStr, genreStr, trackStr, albumArtistStr, composerStr, lyricistStr, commentStr, discStr,
+      (success: boolean, error?: string) => {
+        if (success) {
+          console.log("onecold 编辑信息成功,数据库已同步");
+        } else {
+          console.error("onecold 编辑信息数据库失败原因: " + error);
+        }
+        resolve(success);
+      });
+  });
 }