Explorar o código

文件扫描模块新增校正数据的功能

onecold hai 1 ano
pai
achega
444ef5c9bf

+ 6 - 0
entry/src/main/ets/common/util/MediaTable.ets

@@ -83,6 +83,12 @@ export default class MediaTable {
     this.accountTable.deleteData(predicates, callback);
   }
 
+  deleteDataFilePath(filePath: string, callback: Function) {
+    let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
+    predicates.equalTo('filePath', filePath);
+    this.accountTable.deleteData(predicates, callback);
+  }
+
   deleteDataForParentPath(parentPath:string, callback: Function) {
     let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
     predicates.equalTo('parentPath', parentPath);

+ 6 - 0
entry/src/main/ets/common/util/RdbUtils.ets

@@ -265,6 +265,8 @@ export default class RdbUtils {
           callback(ret);
         });
       });
+    }else{
+      Logger.error(RdbUtils.RDB_TAG, 'RdbStore2 is not initialized.');
     }
   }
 
@@ -279,13 +281,17 @@ export default class RdbUtils {
     if (this.rdbStore) {
       this.rdbStore.delete(predicates, (err, ret) => {
         if (err) {
+          Logger.info('xiaozheng 校正数据开始 deleteData5 = ' )
           Logger.error(RdbUtils.RDB_TAG, `deleteData() failed, err: ${err}`);
           callback(resFlag);
           return;
         }
+        Logger.info('xiaozheng 校正数据开始 deleteData6 = ' )
         Logger.info(RdbUtils.RDB_TAG, `deleteData() finished: ${ret}`);
         callback(!resFlag);
       });
+    }else{
+      Logger.info(RdbUtils.RDB_TAG, 'deleteData rdbStore() 未初始化!');
     }
   }
 

+ 106 - 34
entry/src/main/ets/pages/ScanFilePage.ets

@@ -22,13 +22,16 @@ import { DialogHelper } from '@pura/harmony-dialog'
 // @Entry
 @Component
 export struct ScanFilePage{
+  @StorageProp('mediaKuList')  mediaKuList: Array<VideoItem> = []; //媒体库文件
   @State rootPath:string = '' //音频根目录
   @State lockPath:string = ''
   @Consume isShowDrawer: boolean;
   @Consume offsetX: number;
   @State strText:string = ''
+  @State textVisi:Visibility=Visibility.Hidden
   @State isStart:boolean = false
   @State isStartCover:boolean = false
+  @State isStartSync:boolean = false
   @State appName:string = ''
   //lottie动画构建渲染上下文
   private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true)
@@ -94,14 +97,19 @@ export struct ScanFilePage{
     const eventData: emitter.EventData = {};
     emitter.emit({ eventId: 101 }, eventData); // 发送视频打开广播事件
     this.watchStatus(false)
-    ToastUtil.showToast('扫描文件入库成功!')
     if(isOnekey){
       this.isStartCover = false
+      this.strText = '获取成功!'
     }else{
-      this.isStart = false
+      if(this.isStartSync){
+        this.isStartSync = false
+        this.strText = '校正数据成功!'
+      }else{
+        this.strText = '扫描文件入库成功!'
+        this.isStart = false
+      }
 
     }
-    this.strText = ''
     //结束动画
     lottie.pause()
     lottie.stop()
@@ -122,28 +130,17 @@ export struct ScanFilePage{
   }
 
 
-  // @State titleBarModel: TitleBar.Model = new TitleBar.Model()
-  //   .setTitleTextStyle(FontStyle.Normal)
-  //   .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT)
-  //   .setLeftIcon($r('app.media.left_back_white'))
-  //   .setTitleName("文件扫描")
-  //   .setTitleFontColor(Color.White)
-  //   .setTitleBarBackground(this.themeColor)
-  //   .setLeftTitleBackground(this.themeColor)
-  //   .setTitleBarBottomLineColor(this.themeColor)
-  //   .setOnLeftClickListener(() => {
-  //     router.back()
-  //
-  //   })
   initState(isOnekey:boolean){
-
+    this.textVisi = Visibility.Visible
     this.initLottie(this.path,true)
     if(isOnekey){
+      this.strText = '正在获取'
       this.isStartCover = true
     }else{
+      this.strText = Utility.resourceToString(getContext(this),$r('app.string.scaning'))
       this.isStart = true
     }
-    this.strText = Utility.resourceToString(getContext(this),$r('app.string.scaning'))
+
     lottie.play()
   }
 
@@ -224,11 +221,13 @@ export struct ScanFilePage{
           .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
             .animation({ duration: 380, curve: Curve.Ease,delay:30 }))
 
-          // Text(this.strText)
-          //   .margin({ right: 20,top:20,bottom:20 })
-          //   .fontSize(16)
-          //   .fontColor(Color.Black)
-          //   .fontWeight(480)
+          Text(this.strText)
+            .height(50)
+            .margin({ right: 20 })
+            .fontSize(16)
+            .fontColor($r('app.color.text_color'))
+            .fontWeight(480)
+            .visibility(this.textVisi)
 
 
           Column() {
@@ -274,6 +273,26 @@ export struct ScanFilePage{
             // .width('100%')
             .margin({ left:25,right: 25 ,top:20,bottom:20 })
 
+            Row() {
+
+
+              Image($r('app.media.selected'))
+                .width(16)
+                .height(16)
+                .fillColor(this.themeColor)
+                .margin({ left:10})
+                .alignSelf(ItemAlign.Center)
+              Text($r('app.string.sync_tips'))
+                .margin({ left: 10, right: 20 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+                .fontWeight(480)
+                .layoutWeight(1)
+
+            }
+            // .width('100%')
+            .margin({ left:25,right: 25 ,bottom:20 })
+
           }
           .width(this.currentBreakpoint !== BreakpointTypeEnum.SM?450:350)
           .backgroundColor($r('app.color.index_background'))
@@ -284,16 +303,13 @@ export struct ScanFilePage{
             .animation({ duration: 380, curve: Curve.Ease,delay:60 }))
 
           Column() {
-            Button(this.isStart?'正在扫描':$r('app.string.start_scan'), { type: ButtonType.Capsule, stateEffect: false })
+            Button($r('app.string.start_scan'), { type: ButtonType.Capsule, stateEffect: false })
 
               .width(180)
               .height(55)
               .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
               .margin({ top: 20, bottom: 10 })
-              .linearGradient({
-                direction: GradientDirection.Right,
-                colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
-              })
+              .backgroundColor(this.themeColor)
               .enabled(this.isStart ?false:true)
               .onClick(() => {
                 this.doOptimize(false)
@@ -301,15 +317,12 @@ export struct ScanFilePage{
               })
               .alignSelf(ItemAlign.Center)
 
-            Button(this.isStartCover?'正在扫描':$r('app.string.onekey_cover'), { type: ButtonType.Capsule, stateEffect: false })
+            Button($r('app.string.onekey_cover'), { type: ButtonType.Capsule, stateEffect: false })
               .width(180)
               .height(55)
               .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
-              .margin({ top: 10, bottom: 20 })
-              .linearGradient({
-                direction: GradientDirection.Right,
-                colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
-              })
+              .margin({ top: 10, bottom: 10 })
+              .backgroundColor(this.themeColor)
               .enabled(this.isStartCover ?false:true)
               .onClick(() => {
                 if(PreferencesUtil.getStringSync('COVER_API','')===''){
@@ -321,6 +334,19 @@ export struct ScanFilePage{
               })
               .alignSelf(ItemAlign.Center)
 
+            Button($r('app.string.sync_data'), { type: ButtonType.Capsule, stateEffect: false })
+              .width(180)
+              .height(55)
+              .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
+              .margin({ top: 10, bottom: 20 })
+              .backgroundColor(this.themeColor)
+              .enabled(this.isStartSync ?false:true)
+              .onClick(() => {
+                this.doSyncData()
+
+              })
+              .alignSelf(ItemAlign.Center)
+
 
           }
           .transition(TransitionEffect.move(TransitionEdge.BOTTOM)
@@ -337,6 +363,24 @@ export struct ScanFilePage{
     }
   }
 
+  doSyncData() {
+    this.watchStatus(true)
+    this.initLottie(this.path,true)
+    this.isStartSync = true
+    this.textVisi = Visibility.Visible
+    this.strText = Utility.resourceToString(getContext(this),$r('app.string.sync_dataing'))
+    lottie.play()
+    // 仅提取 filePath 列表
+    const filePaths = this.mediaKuList.map(item => item.filePath);
+    Logger.info('xiaozheng 校正数据开始 this.filePaths length= ' + filePaths.length)
+    const task2 = new taskpool.Task(syncDataTask, getContext(this), filePaths);
+    taskpool.execute(task2, taskpool.Priority.HIGH).then(()=>{
+      this.endScan(false)
+    }).catch((e:object)=>{
+      console.info("task2 catch e: " + e);
+    })
+  }
+
   showTipsDialog() {
     DialogHelper.showCustomContentDialog({
       dialogId: 'tips',
@@ -395,6 +439,34 @@ export struct ScanFilePage{
 
 
 
+//扫描数据库校正对比数据是否真实存在,不存在在删除数据
+@Concurrent
+async function syncDataTask(context: Context, mediaKuList: Array<string>) {
+  const table: MediaTable = new MediaTable(context);
+  for (const item of mediaKuList) {
+    const filePath = item;
+    // 检查 filePath 是否存在
+    const exists:boolean = await FileUtil.accessSync(filePath);
+    // 如果 filePath 不存在,则删除数据库中的数据
+    if (!exists) {
+      table.getRdbStore(context,  async (err:Error) => {
+        if (err) {
+          return;
+        }
+        Logger.info('xiaozheng 校正数据开始 this.exists = ' + exists+' filepath = ' +filePath)
+        await table.deleteDataFilePath(filePath, (result:boolean) => {
+          if(result){
+            Logger.info(`xiaozheng Deleted item success with filePath: ${filePath}`);
+          }
+
+        });
+      })
+
+    }
+  }
+}
+
+//扫描文件入库
 @Concurrent
 async function  scanDirectoryTask(context: Context, dirPath: string, lockPath: string,cover_api:string) {
   const stack: string[] = [dirPath];

+ 2 - 1
entry/src/main/ets/view/LocalMusic.ets

@@ -700,6 +700,7 @@ export struct LocalMusic {
           this.mediaKuList = e.data.data
           Logger.info('onecold 查询媒体库列表 this.mediaKuList length= ' + this.mediaKuList.length)
           Utility.doSortListAscending(this.mediaKuList)
+          AppStorage.setOrCreate('mediaKuList', this.mediaKuList);
           if (this.modeType === 1) {
             this.updateListData(this.mediaKuList)
           }
@@ -3849,7 +3850,7 @@ export struct LocalMusic {
       }
       .width(180)
     }
-    .height(item.type === CommonConstants.TYPE_IS_DIR ? '22%' : '40%')
+    .height(item.type === CommonConstants.TYPE_IS_DIR ? 150 : 400)
   }
 
   private listMaxScrollOffsetY: number = 0

+ 12 - 0
entry/src/main/resources/base/element/string.json

@@ -439,6 +439,18 @@
     {
       "name": "detail",
       "value": "详情"
+    },
+    {
+      "name": "sync_data",
+      "value": "校正数据"
+    },
+    {
+      "name": "sync_tips",
+      "value": "如果你在系统的文件管理删除了音乐媒体文件,可以使用校正数据来删除校正对于的数据库。"
+    },
+    {
+      "name": "sync_dataing",
+      "value": "正在校正数据"
     }
   ]
 }