|
@@ -15,6 +15,7 @@ export struct DeleteComptent {
|
|
|
@State isDeleteYuan: boolean = true
|
|
@State isDeleteYuan: boolean = true
|
|
|
@State isDeletePicture: boolean = true
|
|
@State isDeletePicture: boolean = true
|
|
|
@State isDeleteLrc: boolean = true
|
|
@State isDeleteLrc: boolean = true
|
|
|
|
|
+ @State onlyRemoveFromPlaylist: boolean = false
|
|
|
@State packName: string = ''
|
|
@State packName: string = ''
|
|
|
@State isDeleting: boolean = false // 删除状态
|
|
@State isDeleting: boolean = false // 删除状态
|
|
|
@State deleteProgress: number = 0 // 删除进度 (0-100)
|
|
@State deleteProgress: number = 0 // 删除进度 (0-100)
|
|
@@ -24,6 +25,8 @@ export struct DeleteComptent {
|
|
|
onCancel = () => {
|
|
onCancel = () => {
|
|
|
}
|
|
}
|
|
|
@Prop selectedFiles: Array<VideoItem>
|
|
@Prop selectedFiles: Array<VideoItem>
|
|
|
|
|
+ @Prop isPlaylistMode: boolean = false
|
|
|
|
|
+ @Prop playlistId: string = ''
|
|
|
@StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
|
|
@StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
|
|
|
context = this.getUIContext().getHostContext() as common.UIAbilityContext
|
|
context = this.getUIContext().getHostContext() as common.UIAbilityContext
|
|
|
|
|
|
|
@@ -33,6 +36,9 @@ export struct DeleteComptent {
|
|
|
this.isDeleteYuan = PreferencesUtil.getBooleanSync('isDeleteYuan', true);
|
|
this.isDeleteYuan = PreferencesUtil.getBooleanSync('isDeleteYuan', true);
|
|
|
this.isDeletePicture = PreferencesUtil.getBooleanSync('isDeletePicture', true);
|
|
this.isDeletePicture = PreferencesUtil.getBooleanSync('isDeletePicture', true);
|
|
|
this.isDeleteLrc = PreferencesUtil.getBooleanSync('isDeleteLrc', true)
|
|
this.isDeleteLrc = PreferencesUtil.getBooleanSync('isDeleteLrc', true)
|
|
|
|
|
+ if (!this.isPlaylistMode) {
|
|
|
|
|
+ this.onlyRemoveFromPlaylist = false
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -105,6 +111,47 @@ export struct DeleteComptent {
|
|
|
Text('温馨提醒').fontSize(20).margin({ top: 10, bottom: 10 })
|
|
Text('温馨提醒').fontSize(20).margin({ top: 10, bottom: 10 })
|
|
|
Text('是否删除这些文件?').fontSize(16).margin({ top: 10, bottom: 10 })
|
|
Text('是否删除这些文件?').fontSize(16).margin({ top: 10, bottom: 10 })
|
|
|
Column() {
|
|
Column() {
|
|
|
|
|
+ // 只移除歌单选项(歌单场景)
|
|
|
|
|
+ Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
|
|
|
+ Row() {
|
|
|
|
|
+ SymbolGlyph($r('sys.symbol.music_note_list'))
|
|
|
|
|
+ .fontSize(20)
|
|
|
|
|
+ .fontColor([this.themeColor])
|
|
|
|
|
+ .alignSelf(ItemAlign.Center)
|
|
|
|
|
+ .margin({ left: 15 })
|
|
|
|
|
+ Text("只移除歌单")
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .layoutWeight(1)
|
|
|
|
|
+ .margin({ left: 10 })
|
|
|
|
|
+ Toggle({ type: ToggleType.Checkbox, isOn: this.onlyRemoveFromPlaylist })
|
|
|
|
|
+ .onChange((isOn: boolean) => {
|
|
|
|
|
+ this.onlyRemoveFromPlaylist = isOn;
|
|
|
|
|
+ if (isOn) {
|
|
|
|
|
+ this.isDeleteYuan = false
|
|
|
|
|
+ this.isDeletePicture = false
|
|
|
|
|
+ this.isDeleteLrc = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .margin({ right: 28 })
|
|
|
|
|
+ .selectedColor(this.themeColor)
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
|
|
+ .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
|
|
|
|
|
+ .onClick(() => {
|
|
|
|
|
+ this.onlyRemoveFromPlaylist = !this.onlyRemoveFromPlaylist
|
|
|
|
|
+ if (this.onlyRemoveFromPlaylist) {
|
|
|
|
|
+ this.isDeleteYuan = false
|
|
|
|
|
+ this.isDeletePicture = false
|
|
|
|
|
+ this.isDeleteLrc = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .width('100%')
|
|
|
|
|
+ .padding(10)
|
|
|
|
|
+ .margin({ left: 18 })
|
|
|
|
|
+ .visibility(this.isPlaylistMode ? Visibility.Visible : Visibility.None)
|
|
|
|
|
+
|
|
|
// 删除源文件选项
|
|
// 删除源文件选项
|
|
|
Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
|
Row() {
|
|
Row() {
|
|
@@ -135,6 +182,7 @@ export struct DeleteComptent {
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.padding(10)
|
|
.padding(10)
|
|
|
.margin({ left: 18 })
|
|
.margin({ left: 18 })
|
|
|
|
|
+ .visibility(this.onlyRemoveFromPlaylist ? Visibility.None : Visibility.Visible)
|
|
|
|
|
|
|
|
// 删除封面选项
|
|
// 删除封面选项
|
|
|
Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
@@ -165,6 +213,7 @@ export struct DeleteComptent {
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.padding(10)
|
|
.padding(10)
|
|
|
.margin({ left: 18 })
|
|
.margin({ left: 18 })
|
|
|
|
|
+ .visibility(this.onlyRemoveFromPlaylist ? Visibility.None : Visibility.Visible)
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除歌词选项
|
|
// 删除歌词选项
|
|
@@ -197,6 +246,7 @@ export struct DeleteComptent {
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.padding(10)
|
|
.padding(10)
|
|
|
.margin({ left: 18, bottom: 10 })
|
|
.margin({ left: 18, bottom: 10 })
|
|
|
|
|
+ .visibility(this.onlyRemoveFromPlaylist ? Visibility.None : Visibility.Visible)
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
.visibility(this.selectedFiles.length==1&&this.selectedFiles[0].type==CommonConstants.TYPE_IS_DIR?
|
|
.visibility(this.selectedFiles.length==1&&this.selectedFiles[0].type==CommonConstants.TYPE_IS_DIR?
|
|
@@ -233,6 +283,11 @@ export struct DeleteComptent {
|
|
|
|
|
|
|
|
|
|
|
|
|
doDeleteTask(){
|
|
doDeleteTask(){
|
|
|
|
|
+ if (this.onlyRemoveFromPlaylist && StrUtil.isEmpty(this.playlistId)) {
|
|
|
|
|
+ ToastUtil.showToast('当前歌单信息无效')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 设置删除状态
|
|
// 设置删除状态
|
|
|
this.isDeleting = true;
|
|
this.isDeleting = true;
|
|
|
this.deleteProgress = 0;
|
|
this.deleteProgress = 0;
|
|
@@ -255,11 +310,18 @@ export struct DeleteComptent {
|
|
|
}
|
|
}
|
|
|
}, 300); // 每300ms更新一次,模拟删除进度
|
|
}, 300); // 每300ms更新一次,模拟删除进度
|
|
|
|
|
|
|
|
- const task = new taskpool.Task(
|
|
|
|
|
- deleteMultipleFilesWithProgress,
|
|
|
|
|
- JSON.stringify(this.selectedFiles),
|
|
|
|
|
- this.isDeleteYuan,this.isDeletePicture,this.isDeleteLrc,this.context,this.packName
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const task = this.onlyRemoveFromPlaylist ?
|
|
|
|
|
+ new taskpool.Task(
|
|
|
|
|
+ removeSongsFromPlaylistOnly,
|
|
|
|
|
+ JSON.stringify(this.selectedFiles),
|
|
|
|
|
+ this.context,
|
|
|
|
|
+ this.playlistId
|
|
|
|
|
+ ) :
|
|
|
|
|
+ new taskpool.Task(
|
|
|
|
|
+ deleteMultipleFilesWithProgress,
|
|
|
|
|
+ JSON.stringify(this.selectedFiles),
|
|
|
|
|
+ this.isDeleteYuan, this.isDeletePicture, this.isDeleteLrc, this.context, this.packName
|
|
|
|
|
+ );
|
|
|
taskpool.execute(task, taskpool.Priority.HIGH).then((result) => {
|
|
taskpool.execute(task, taskpool.Priority.HIGH).then((result) => {
|
|
|
clearInterval(progressTimer);
|
|
clearInterval(progressTimer);
|
|
|
this.deleteProgress = 100;
|
|
this.deleteProgress = 100;
|
|
@@ -283,6 +345,54 @@ export struct DeleteComptent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+// 仅从当前歌单移除歌曲
|
|
|
|
|
+@Concurrent
|
|
|
|
|
+async function removeSongsFromPlaylistOnly(
|
|
|
|
|
+ selectedFilesStr:string,
|
|
|
|
|
+ context:Context,
|
|
|
|
|
+ playlistId:string
|
|
|
|
|
+) {
|
|
|
|
|
+ const selectedFiles: VideoItem[] = JSON.parse(selectedFilesStr)
|
|
|
|
|
+ if (!ArrayUtil.isNotEmpty(selectedFiles)) {
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isEmpty(playlistId)) {
|
|
|
|
|
+ LogUtil.error('heanup DeleteComptent', 'removeSongsFromPlaylistOnly: playlistId 为空')
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const playlistTable: PlaylistTable = new PlaylistTable(context)
|
|
|
|
|
+ let hasPlaylistChanges = false
|
|
|
|
|
+ let hasError = false
|
|
|
|
|
+
|
|
|
|
|
+ for (let i = 0; i < selectedFiles.length; i++) {
|
|
|
|
|
+ const item = selectedFiles[i]
|
|
|
|
|
+ if (!item.filePath) {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ const removed = await playlistTable.removeSongFromPlaylist(playlistId, item.filePath)
|
|
|
|
|
+ if (removed) {
|
|
|
|
|
+ hasPlaylistChanges = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ hasError = true
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ hasError = true
|
|
|
|
|
+ LogUtil.error('heanup DeleteComptent', `removeSongsFromPlaylistOnly error: ${(error as Error).message}`)
|
|
|
|
|
+ }
|
|
|
|
|
+ await new Promise<void>(resolve => setTimeout(resolve, 120))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (hasPlaylistChanges) {
|
|
|
|
|
+ const eventRefresh: emitter.InnerEvent = { eventId: EventConstants.EVENT_PLAYLIST_REFRESH }
|
|
|
|
|
+ emitter.emit(eventRefresh, {})
|
|
|
|
|
+ emitter.emit({ eventId: EventConstants.EVENT_PLAYLIST_REFRESH_SORT }, {})
|
|
|
|
|
+ }
|
|
|
|
|
+ return !hasError
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
//多选删除文件(带进度显示的新版本)
|
|
//多选删除文件(带进度显示的新版本)
|
|
|
@Concurrent
|
|
@Concurrent
|
|
|
async function deleteMultipleFilesWithProgress(
|
|
async function deleteMultipleFilesWithProgress(
|