Преглед изворни кода

增加表字段
扫描文件页面增加一键获取封面按钮
提示用户可以加q群讨论

onecold пре 1 година
родитељ
комит
02e551f808

+ 12 - 1
entry/src/main/ets/common/util/MediaTable.ets

@@ -223,7 +223,8 @@ export default class MediaTable {
       obj.lastPlayedStr  = resultSet.getString(resultSet.getColumnIndex('lastPlayedStr'));
       obj.playCount  = resultSet.getDouble(resultSet.getColumnIndex('playCount'));
       obj.lyricContent  = resultSet.getString(resultSet.getColumnIndex('lyricContent'));
-
+      obj.md5Str  = resultSet.getString(resultSet.getColumnIndex('md5Str'));
+      obj.extra_json  = resultSet.getString(resultSet.getColumnIndex('extra_json'));
       const valueBucket: relationalStore.ValuesBucket = obj
       // Step 4: 执行更新
       const updatePredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
@@ -459,6 +460,9 @@ export default class MediaTable {
     item.playCount = safeGetNumber(DB_COLUMNS.PLAY_COUNT);
     item.lyricContent = safeGet(DB_COLUMNS.LYRIC_CONTENT);
 
+    item.md5Str = safeGet('md5Str');
+    item.extra_json = safeGet('extra_json');
+
     return item;
   }
 
@@ -520,6 +524,13 @@ function generateBucket(item: VideoItem): relationalStore.ValuesBucket {
   if(item.lyricContent){
     obj.lyricContent = item.lyricContent;
   }
+  if(item.md5Str){
+    obj.md5Str = item.md5Str;
+  }
+  if(item.extra_json){
+    obj.extra_json = item.extra_json;
+  }
+
 
   return obj;
 }

+ 5 - 1
entry/src/main/ets/common/util/RdbUtils.ets

@@ -58,12 +58,14 @@ export default class RdbUtils {
       '        lastPlayedStr TEXT,\n' +
       '        trackCount TEXT,\n' +
       '        lyricContent TEXT,\n' +
+      '        md5Str TEXT,\n' +
+      '        extra_json TEXT,\n' +
       '        mimeType TEXT' +
       ')',
     columns: ['id', 'name', 'filePath','mtype', 'videoSize', 'cTime','size', 'artist', 'album',
       'fileName','parentPath','isFav','pixelMapPath','pixelMapToString',
       'duration',   'sampleRate','playCount',  'lastPlayedStr', 'trackCount',
-      'lyricContent','mimeType']
+      'lyricContent','md5Str','extra_json','mimeType']
   };
 
   constructor(tableName: string, sqlCreateTable: string, columns: Array<string>) {
@@ -133,6 +135,8 @@ export default class RdbUtils {
             'lastPlayedStr': 'TEXT',
             'trackCount': 'TEXT',
             'lyricContent': 'TEXT',
+            'md5Str': 'TEXT',
+            'extra_json': 'TEXT',
             'mimeType': 'TEXT'
           };
           

+ 81 - 57
entry/src/main/ets/pages/ScanFilePage.ets

@@ -14,6 +14,7 @@ import { CommonConstants } from '../common/constants/CommonConstants'
 import { emitter } from '@kit.BasicServicesKit'
 import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
 import { resourceManager } from '@kit.LocalizationKit'
+import { DialogHelper } from '@pura/harmony-dialog'
 
 
 @Preview
@@ -25,6 +26,7 @@ export struct ScanFilePage{
 
   @State strText:string = ''
   @State isStart:boolean = false
+  @State isStartCover:boolean = false
   @State appName:string = ''
   //lottie动画构建渲染上下文
   private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true)
@@ -73,6 +75,7 @@ export struct ScanFilePage{
 
     ToastUtil.showToast('扫描文件入库成功!')
     this.isStart = false
+    this.isStartCover = false
     this.strText = ''
     //结束动画
     lottie.pause()
@@ -107,6 +110,7 @@ export struct ScanFilePage{
 
     this.initLottie(this.path,true)
     this.isStart = true
+    this.isStartCover = true
     this.strText = Utility.resourceToString(getContext(this),$r('app.string.scaning'))
     lottie.play()
   }
@@ -225,7 +229,7 @@ export struct ScanFilePage{
 
               .width('60%')
               .height(55)
-              .margin({ top: 30, bottom: 20 })
+              .margin({ top: 20, bottom: 10 })
               .linearGradient({
                 direction: GradientDirection.Right,
                 colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
@@ -237,6 +241,26 @@ export struct ScanFilePage{
               })
               .alignSelf(ItemAlign.Center)
 
+            Button(this.isStartCover?'正在扫描':$r('app.string.onekey_cover'), { type: ButtonType.Capsule, stateEffect: false })
+
+              .width('60%')
+              .height(55)
+              .margin({ top: 10, bottom: 20 })
+              .linearGradient({
+                direction: GradientDirection.Right,
+                colors: [['#ff37a0fc', 0.0], ['#67e667', 0.5], ['#f5856e', 1.0]]
+              })
+              .enabled(this.isStartCover ?false:true)
+              .onClick(() => {
+                if(PreferencesUtil.getStringSync('COVER_API','')===''){
+                  this.showTipsDialog()
+                  return
+                }
+                this.doOptimize()
+
+              })
+              .alignSelf(ItemAlign.Center)
+
 
           }
 
@@ -251,65 +275,65 @@ export struct ScanFilePage{
     }
   }
 
-}
+  showTipsDialog() {
+    DialogHelper.showCustomContentDialog({
+      dialogId: 'tips',
+      title: "友情提示",
+      autoCancel: false, //点击遮障层时,不关闭弹窗
+      backCancel: true, //点击返回键,不关闭弹窗
+      contentBuilder: () => {
+        this.customTipsBuilder("请到设置界面配置封面服务器地址!")
+      },
+      buttons: [],
+    })
+  }
 
+  @Builder
+  customTipsBuilder(content: string) {
+    Column() {
+      Text(content)
+        .fontColor(Color.Gray)
+        .fontSize(16)
+        .alignSelf(ItemAlign.Start)
+        .margin({ bottom: 15 })
+        .fontSize(16)
+
+      Row() {
+        Button('教程')
+          .fontColor(Color.White)
+          .backgroundColor($r('app.color.title_bar_bg'))//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
+          .height(50)
+          .layoutWeight(1)
+          .stateEffect(true)
+          .margin({ right: 6 })
+          .onClick(() => {
+            ToastUtil.showToast('欢迎进群学习教程,复制Q群号成功!')
+            Utility.copyText('685109858')
+            DialogHelper.closeDialog('tips'); //关闭弹框
+          })
+        Button('跳转')
+          .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
+          .layoutWeight(1)
+          .height(50)
+          .backgroundColor($r('app.color.title_bar_bg'))
+          .stateEffect(true)
+          .margin({ left: 6 })
+          .onClick(() => {
+            DialogHelper.closeDialog('tips'); //关闭弹框
+            router.pushUrl({
+              url: 'pages/SettingPage'
+            }, router.RouterMode.Single);
+          })
+      }
+
+    }
+    .width("100%")
+    .padding(10)
+  }
+
+}
 
 
-// async function scanDirectoryTask(context: Context, curPath: string, lockPath: string) {
-//   const table: MediaTable = new MediaTable(context);
-//
-//
-//   try {
-//     // 使用 Promise 包装数据库操作
-//     await new Promise<void>((resolve, reject) => {
-//       table.getRdbStore(context,  async (err:Error) => {
-//         if (err) {
-//           reject(err);
-//           return;
-//         }
-//
-//         const files = FileUtil.listFileSync(curPath);
-//         const pendingTasks: Promise<void>[] = [];
-//
-//         for (const file of files) {
-//           const fPath = `${curPath}/${file}`;
-//           if (fPath === lockPath) continue;
-//
-//           if (FileUtil.isDirectory(fPath))  {
-//             // 用立即执行函数处理异步递归
-//             pendingTasks.push((async  () => {
-//               await scanDirectoryTask(context, fPath, lockPath);
-//             })());
-//           } else {
-//             if(!fPath.endsWith('.lrc')&&Utility.isMeidaByExtension(fPath)&&!fPath.endsWith('.srt')){
-//               // 用 Promise 包装媒体处理逻辑
-//               pendingTasks.push((async  () => {
-//                 let mediaItem:VideoItem = await Utility.uriGetMusicAssetsFromFile(context, fPath, CommonConstants.TYPE_LOCAL, true);
-// ;
-//                 await new Promise<void>((resolve: (value: void) => void) => {
-//                   table.insert(mediaItem,  (id: number) => {
-//                     resolve(); // 明确调用 resolve 且无返回值
-//                   });
-//                 });
-//               })());
-//             }
-//           }
-//         }
-//
-//         // 关键点:等待所有异步操作完成
-//         await Promise.all(pendingTasks);
-//         resolve();
-//       });
-//     });
-//
-//     // Logger.info('onecold scanDirectory 全部扫描完成后执行 = ')
-//
-//   } catch (err) {
-//     Logger.error(`Scan  failed: ${err.code}  - ${err.message}`);
-//   }
-//
-//
-// }
 
 @Concurrent
 async function  scanDirectoryTask(context: Context, dirPath: string, lockPath: string,cover_api:string) {

+ 19 - 0
entry/src/main/ets/pages/SettingPage.ets

@@ -10,6 +10,7 @@ import { fileIo, fileUri } from '@kit.CoreFileKit'
 import { BusinessError, emitter } from '@kit.BasicServicesKit'
 import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
 import { resourceManager } from '@kit.LocalizationKit'
+import { Utility } from '../common/util/Utility'
 
 @Preview
 @Entry
@@ -626,6 +627,24 @@ export struct SettingPage {
             })
             .justifyContent(FlexAlign.Center)
             .height(55)
+
+            Row() {
+              Text('API设置教程:')
+                .margin({ left: 18, right: 6 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+              Text('欢迎进Q群讨论:685109858')
+                .margin({ right: 10 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+                .layoutWeight(1)
+            }
+            .onClick(() => {
+              ToastUtil.showToast('复制群号成功!')
+              Utility.copyText('685109858')
+            })
+            .justifyContent(FlexAlign.Center)
+            .height(55)
           }
           .backgroundColor($r('app.color.settings_background_main'))
           .borderRadius(20)

+ 64 - 23
entry/src/main/ets/view/LocalMusic.ets

@@ -2178,6 +2178,7 @@ export struct LocalMusic {
       $r('app.media.music_group'))
         .height(33)
         .width(33)
+        .fillColor('#FF4081')
         .alt($r('app.media.music_group'))
         .borderRadius('100%')
         .clip(true)
@@ -5242,7 +5243,7 @@ export struct LocalMusic {
     this.lyricTextWeightPip = PreferencesUtil.getNumberSync('lyricTextWeightPip',400)
     this.lyricControllerXF.setTextWeight(this.lyricTextWeightPip)
 
-    this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#E8E8E8')
+    this.pipBg = PreferencesUtil.getStringSync('BGColorPip', '#FFFF54')
     this.nodeController.updateBgColor(this.pipBg,this.lyricControllerXF)
   }
 
@@ -6555,8 +6556,6 @@ export struct LocalMusic {
       Row() {
         this.pushLyricButton($r('app.media.cut_current'), 0, '本地歌词')
         this.pushLyricButton($r('app.media.white_search'),  1, '获取歌词')
-        // this.pushLyricButton($r('app.media.white_search'),  2, '获取歌词')
-
 
       }
       .justifyContent(FlexAlign.Center)
@@ -6782,8 +6781,9 @@ export struct LocalMusic {
           break;
         case 1:
           //判断是不是赞助会员
-          if(PreferencesUtil.getStringSync('LRC_API','')===''){
-            ToastUtil.showToast('请到设置界面配置歌词服务器地址')
+          if(PreferencesUtil.getStringSync('COVER_API','')===''){
+            this.isLyricSetting = false
+            this.showTipsDialog()
             return
           }
           if (StrUtil.isNotEmpty(this.videoUrl)) {
@@ -6792,23 +6792,6 @@ export struct LocalMusic {
             let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
             this.initLyric(lyricPath, true);
           }
-
-
-          break;
-        case 2:
-          //判断是不是赞助会员
-          // if(Utility.isNoble()){
-          if (StrUtil.isNotEmpty(this.videoUrl)) {
-            ToastUtil.showToast('正在获取')
-            this.isLyricSetting = false
-            let lyricPath = this.videoUrl.substring(0, this.videoUrl.lastIndexOf('.')) + '.lrc'
-            this.initLyric(lyricPath, true, true);
-          }
-          // }else{
-          //   this.isLyricSetting = false
-          //   this.showVipDialog()
-          // }
-
           break;
       }
     })
@@ -6880,6 +6863,63 @@ export struct LocalMusic {
     .padding(10)
   }
 
+  showTipsDialog() {
+    DialogHelper.showCustomContentDialog({
+      dialogId: 'tips',
+      title: "友情提示",
+      autoCancel: false, //点击遮障层时,不关闭弹窗
+      backCancel: true, //点击返回键,不关闭弹窗
+      contentBuilder: () => {
+        this.customTipsBuilder("请到设置界面配置封面服务器地址!")
+      },
+      buttons: [],
+    })
+  }
+
+  @Builder
+  customTipsBuilder(content: string) {
+    Column() {
+      Text(content)
+        .fontColor(Color.Gray)
+        .fontSize(16)
+        .alignSelf(ItemAlign.Start)
+        .margin({ bottom: 15 })
+        .fontSize(16)
+
+      Row() {
+        Button('教程')
+          .fontColor(Color.White)
+          .backgroundColor($r('app.color.title_bar_bg'))//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
+          .height(50)
+          .layoutWeight(1)
+          .stateEffect(true)
+          .margin({ right: 6 })
+          .onClick(() => {
+            ToastUtil.showToast('欢迎进群学习教程,复制Q群号成功!')
+            Utility.copyText('685109858')
+            DialogHelper.closeDialog('tips'); //关闭弹框
+          })
+        Button('跳转')
+          .fontColor(Color.White)//.linearGradient( { direction: GradientDirection.Right, colors:[['#ff37a0fc',0.0],['#67e667',0.5],['#f5856e',1.0]]})
+          .layoutWeight(1)
+          .height(50)
+          .backgroundColor($r('app.color.title_bar_bg'))
+          .stateEffect(true)
+          .margin({ left: 6 })
+          .onClick(() => {
+            DialogHelper.closeDialog('tips'); //关闭弹框
+            this.isShowPlay = false
+            router.pushUrl({
+              url: 'pages/SettingPage'
+            }, router.RouterMode.Single);
+          })
+      }
+
+    }
+    .width("100%")
+    .padding(10)
+  }
+
   @Builder
   PlayMoreSheet() {
     Column() {
@@ -7426,7 +7466,8 @@ export struct LocalMusic {
 
   doSearchCover(item:VideoItem){
     if(PreferencesUtil.getStringSync('COVER_API','')===''){
-      ToastUtil.showToast('请到设置界面配置封面服务器地址')
+      this.isShowMoreView = false
+      this.showTipsDialog()
       return
     }
     if (item !== undefined) {

+ 4 - 2
entry/src/main/ets/viewmodel/VideoItem.ets

@@ -45,7 +45,8 @@ export class VideoItem  {
   playCount?:number//播放次数
   lyricContent?:string//歌词内容
 
-
+  md5Str?:string
+  extra_json?:string
 
   constructor(name: string, id: string, filePath: string, type:number,videoSize:number,cTime: string,pixelMap?: image.PixelMap,
     size?: string,pixelMapPath?: string,artist?: string,album?: string,fileName?: string, lastPlayed?:Date) {
@@ -70,6 +71,7 @@ export class VideoItem  {
     this.fileName = fileName;
     this.lastPlayed = lastPlayed;
     this.playCount = 0
-
+    this.md5Str = ''
+    this.extra_json = ''
   }
 }

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

@@ -427,6 +427,10 @@
     {
       "name": "rename",
       "value": "重命名"
+    },
+    {
+      "name": "onekey_cover",
+      "value": "一键获取封面"
     }
   ]
 }

BIN
entry/src/main/resources/base/media/music_group.png


+ 1 - 0
entry/src/main/resources/base/media/music_group.svg

@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1749978735414" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="36876" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><path d="M566.613333 583.111111c-6.826667-10.24-11.946667-17.635556-17.066666-25.031111-52.906667-76.231111-105.244444-153.031111-159.288889-228.124444-17.635556-24.462222-11.377778-43.235556 4.551111-62.577778 22.755556-27.875556 54.613333-40.96 88.177778-49.493334 53.475556-13.084444 106.951111-25.031111 151.893333-59.164444 24.462222 87.608889-5.688889 179.2-154.737778 187.733333 4.551111 7.964444 7.964444 15.36 11.946667 22.186667 53.475556 89.315556 105.244444 179.2 160.426667 267.377778 71.68 114.346667-29.582222 219.022222-126.293334 227.555555-47.217778 3.982222-94.435556 5.12-134.257778-30.151111-51.768889-44.942222-62.008889-121.742222-19.911111-175.786666 38.115556-48.924444 88.746667-74.524444 151.324445-74.524445h43.235555z" p-id="36877"></path><path d="M512 56.888889c250.88 0 455.111111 204.231111 455.111111 455.111111s-204.231111 455.111111-455.111111 455.111111-455.111111-204.231111-455.111111-455.111111 204.231111-455.111111 455.111111-455.111111m0-56.888889a512 512 0 1 0 0.056889 1024.056889A512 512 0 0 0 512 0z" p-id="36878"></path></svg>