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

新增歌词API自定义设置入口

chendeben пре 1 година
родитељ
комит
cd49e1aaa9

+ 7 - 7
entry/src/main/ets/common/util/NetAxiosUtil.ets

@@ -1,7 +1,7 @@
 
 import { CommonConstants } from '../constants/CommonConstants'
 import { JSON, uri } from '@kit.ArkTS'
-import { LogUtil, StrUtil } from '@pura/harmony-utils'
+import { LogUtil, PreferencesUtil, StrUtil } from '@pura/harmony-utils'
 import { http } from '@kit.NetworkKit'
 
 
@@ -15,14 +15,14 @@ class NetAxiosUtil{
     if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
       artist = ''
     }
-    let requestUrl = CommonConstants.LRC_API
+    let requestUrl = PreferencesUtil.getStringSync('LRC_API')
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 
-
-    if(isApi2){
-       requestUrl = CommonConstants.LRC_API_2
-         + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
-    }
+    LogUtil.debug("Heanup requestUrl =" + requestUrl + '; title = '+title+'; artist = '+artist)
+    // if(isApi2){
+    //    requestUrl = CommonConstants.LRC_API_2
+    //      + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
+    // }
     // LogUtil.debug("onecold requestUrl =" + requestUrl + ' title = '+title+' artist = '+artist)
 
     try {

+ 2 - 11
entry/src/main/ets/pages/NewIndex.ets

@@ -1,20 +1,13 @@
-import { AppUtil, ArrayUtil, DisplayUtil, GlobalContext,
-  JSONUtil,
-  PickerUtil,
-  PreferencesUtil, StrUtil,
-  ToastUtil } from '@pura/harmony-utils';
+import { AppUtil, DisplayUtil, ToastUtil } from '@pura/harmony-utils';
 import TitleBar from '../view/TitleBar';
 import { router } from '@kit.ArkUI';
 import mainViewModel, { MainViewModel } from '../viewmodel/MainViewModel';
 import ItemData from '../viewmodel/ItemData';
 import { CommonConstants } from '../common/constants/CommonConstants';
-import { ToolView } from '../view/ToolView';
 import { VideoItem } from '../viewmodel/VideoItem';
 import ScreenUtil from '../common/util/ScreenUtil';
-import Logger from '../common/util/Logger';
 import { Utility } from '../common/util/Utility';
-import { photoAccessHelper } from '@kit.MediaLibraryKit';
-import { BusinessError, emitter } from '@kit.BasicServicesKit';
+import { emitter } from '@kit.BasicServicesKit';
 import { common } from '@kit.AbilityKit';
 import { AdSlot, AdSlotBuilder,
   CSJAdCreator,
@@ -27,8 +20,6 @@ import { StreamContent } from '../view/StreamContent';
 import { AvSessionController } from '../controller/AvSessionController';
 import { ImageKnife } from '@ohos/imageknife';
 import { BreakpointSystem, BreakpointTypeEnum } from '../common/util/BreakpointSystem';
-import { bundleManager } from '@kit.AbilityKit';
-import { hilog } from '@kit.PerformanceAnalysisKit';
 
 const TAG = 'NewIndex'; // 日志标签
 

+ 41 - 171
entry/src/main/ets/pages/SettingPage.ets

@@ -1,5 +1,5 @@
 import TitleBar from '../view/TitleBar'
-import { router } from '@kit.ArkUI'
+import { promptAction, router } from '@kit.ArkUI'
 import { CommonConstants } from '../common/constants/CommonConstants'
 import { AppUtil, PreferencesUtil } from '@pura/harmony-utils'
 import { Utility } from '../common/util/Utility'
@@ -9,6 +9,7 @@ import { AvSessionController } from '../controller/AvSessionController'
 @Entry
 @Component
 export struct SettingPage{
+  @State lyricApiUrl: string = PreferencesUtil.getStringSync('LRC_API', 'https://lrc.ss5.xyz/jsonapi')
 
   @State isBgPlayOpen:boolean = true   //是否启用后台播放
   @State isAutoRatate:boolean = true   //是否启用自动横竖屏
@@ -65,253 +66,122 @@ export struct SettingPage{
   build() {
     Column(){
       TitleBar({model:$titleBarModel})
-
-
       Column() {
-
-
-        //视频设置
+        //音频设置
         Row() {
-
-          Text('视频设置')
+          Text('音频设置')
             .margin({ left: 38, right: 20 })
             .fontSize(16)
             .fontColor(Color.Gray)
             .fontWeight(480)
           Blank()
-
         }
         .width('100%')
         .height(55)
-
-
-
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
-
-
-        //后台播放
         Row() {
-          Image($r('app.media.video_s'))
+          Image($r('app.media.kp_music_nor'))
             .width(22)
             .height(22)
             .alignSelf(ItemAlign.Center)
             .margin({ left: 28 })
-          Text('投屏和后台播放')
+          Text('记忆播放')
             .margin({ left: 10, right: 20 })
             .fontSize(15)
             .fontColor(Color.Gray)
             .fontWeight(480)
           Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isBgPlayOpen  })
+          Toggle({ type: ToggleType.Switch,isOn: this.isMusicMemoryPlay  })
             .selectedColor($r('app.color.title_bar_bg')) // 设置开关打开时的背景颜色为蓝色
             .switchPointColor(Color.White) // 设置开关关闭时的滑块颜色为白色
             .margin({ right: 28 })
             .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isBgPlayOpen = checked;
-              PreferencesUtil.put(SettingPage.IS_BGPLAY_OPEN,this.isBgPlayOpen)
-              if(!this.isBgPlayOpen){
-                AvSessionController.getInstance(true).unregisterSessionListener()
-              }
-            })
-            .width(50)
-            .height(30);
-
-
-        }
-        .width('100%')
-        .height(55)
-
-
-
-        Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
-
-        //视频自动横竖屏
-        Row() {
-          Image($r('app.media.video_s'))
-            .width(22)
-            .height(22)
-            .alignSelf(ItemAlign.Center)
-            .margin({ left: 28 })
-          Text('自动横竖屏')
-            .margin({ left: 10, right: 20 })
-            .fontSize(15)
-            .fontColor(Color.Gray)
-            .fontWeight(480)
-          Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isAutoRatate  })
-            .selectedColor($r('app.color.title_bar_bg'))
-            .switchPointColor(Color.White)
-            .margin({ right: 28 })
-            .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isAutoRatate = checked;
-              PreferencesUtil.put(SettingPage.IS_AUTO_RATATE,this.isAutoRatate)
-
-            })
-            .width(50)
-            .height(30);
-
-
-        }
-        .width('100%')
-        .height(55)
-
-        Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
-        //开启记忆播放
-        Row() {
-          Image($r('app.media.video_s'))
-            .width(22)
-            .height(22)
-            .alignSelf(ItemAlign.Center)
-            .margin({ left: 28 })
-          Text('记忆播放')
-            .margin({ left: 10, right: 20 })
-            .fontSize(15)
-            .fontColor(Color.Gray)
-            .fontWeight(480)
-          Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isMemoryPlay  })
-            .selectedColor($r('app.color.title_bar_bg'))
-            .switchPointColor(Color.White)
-            .margin({ right: 28 })
-            .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isMemoryPlay = checked;
-              PreferencesUtil.put(SettingPage.iS_MEMORY_PLAY,this.isMemoryPlay)
-
+              this.isMusicMemoryPlay = checked;
+              PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY,this.isMusicMemoryPlay)
             })
             .width(50)
             .height(30);
-
-
         }
         .width('100%')
         .height(55)
-
-
-
-
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
-        //开启硬件解码
         Row() {
-          Image($r('app.media.video_s'))
+          Image($r('app.media.kp_music_nor'))
             .width(22)
             .height(22)
             .alignSelf(ItemAlign.Center)
             .margin({ left: 28 })
-          Text('硬件解码')
+          Text('播放背景随音乐封面')
             .margin({ left: 10, right: 20 })
             .fontSize(15)
             .fontColor(Color.Gray)
             .fontWeight(480)
           Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isMediacodec  })
+          Toggle({ type: ToggleType.Switch,isOn: this.isMusicBGCover  })
             .selectedColor($r('app.color.title_bar_bg')) // 设置开关打开时的背景颜色为蓝色
             .switchPointColor(Color.White) // 设置开关关闭时的滑块颜色为白色
             .margin({ right: 28 })
             .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isMediacodec = checked;
-              PreferencesUtil.put(SettingPage.IS_BGPLAY_OPEN,this.isMediacodec)
+              this.isMusicBGCover = checked;
+              PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER,this.isMusicBGCover)
 
             })
             .width(50)
             .height(30);
-
-
         }
         .width('100%')
         .height(55)
+        Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
-
-      }
-      .backgroundColor(Color.White)
-      .visibility(Visibility.None)
-      .margin({left:15,right:15,top:20,bottom:10})
-      .borderRadius(30)
-
-
-
-      Column() {
-
-        //音频设置
+        //第三方歌词API设置
         Row() {
-
-          Text('音频设置')
+          Text('第三方歌词API设置')
             .margin({ left: 38, right: 20 })
             .fontSize(16)
             .fontColor(Color.Gray)
             .fontWeight(480)
-          Blank()
-
         }
         .width('100%')
         .height(55)
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
         Row() {
-          Image($r('app.media.kp_music_nor'))
-            .width(22)
-            .height(22)
-            .alignSelf(ItemAlign.Center)
-            .margin({ left: 28 })
-          Text('记忆播放')
-            .margin({ left: 10, right: 20 })
+          TextArea({ text: this.lyricApiUrl })
+            .margin({ left: 18, right: 10, top: 8, bottom: 8 })
             .fontSize(15)
-            .fontColor(Color.Gray)
-            .fontWeight(480)
-          Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isMusicMemoryPlay  })
-            .selectedColor($r('app.color.title_bar_bg')) // 设置开关打开时的背景颜色为蓝色
-            .switchPointColor(Color.White) // 设置开关关闭时的滑块颜色为白色
-            .margin({ right: 28 })
-            .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isMusicMemoryPlay = checked;
-              PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY,this.isMusicMemoryPlay)
-
+            .fontColor(Color.Black)
+            .backgroundColor(0xf5f5f5)
+            .borderRadius(10)
+            .layoutWeight(1)
+            .onChange((val: string) => {
+              this.lyricApiUrl = val
             })
-            .width(50)
-            .height(30);
-
-
-        }
-        .width('100%')
-        .height(55)
-
-        Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
-        Row() {
-          Image($r('app.media.kp_music_nor'))
-            .width(22)
-            .height(22)
-            .alignSelf(ItemAlign.Center)
-            .margin({ left: 28 })
-          Text('播放背景随音乐封面')
-            .margin({ left: 10, right: 20 })
+          Button('保存', { type: ButtonType.Normal, stateEffect: true })
+            .borderRadius(8)
+            .backgroundColor(0x317aff)
+            .fontColor(Color.White)
             .fontSize(15)
-            .fontColor(Color.Gray)
-            .fontWeight(480)
-          Blank()
-          Toggle({ type: ToggleType.Switch,isOn: this.isMusicBGCover  })
-            .selectedColor($r('app.color.title_bar_bg')) // 设置开关打开时的背景颜色为蓝色
-            .switchPointColor(Color.White) // 设置开关关闭时的滑块颜色为白色
-            .margin({ right: 28 })
-            .onChange((checked: boolean) => { // 选择开关状态变化时触发事件
-              this.isMusicBGCover = checked;
-              PreferencesUtil.put(SettingPage.iS_MUSIC_BG_COVER,this.isMusicBGCover)
+            .width(80)
+            .height(38)
+            .margin({ left: 10, right: 18 })
+            .onClick(() => {
+              PreferencesUtil.put('LRC_API', this.lyricApiUrl)
+              this.getUIContext().getPromptAction().showToast({
+                message: "保存成功,当前LRC_API:"+ this.lyricApiUrl,
+                duration: 2000,
+                showMode: promptAction.ToastShowMode.TOP_MOST,
+                bottom: 85
+              });
 
             })
-            .width(50)
-            .height(30);
-
-
         }
         .width('100%')
-        .height(55)
-
-        Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+        .margin({top: 8, bottom: 12})
 
       }
       .backgroundColor(Color.White)
       .margin({left:15,right:15,top:20,bottom:10})
       .borderRadius(30)
     }
-
     .backgroundColor($r('app.color.index_background'))
     .height('100%')
 

Разлика између датотеке није приказан због своје велике величине
+ 245 - 230
entry/src/main/ets/view/LocalMusic.ets


+ 1 - 0
entry/src/main/ets/viewmodel/MainViewModel.ets

@@ -75,6 +75,7 @@ export  class  MainViewModel{
 
       new ItemData($r('app.string.yszc'), $r('app.media.oh_pri'),MainViewModel.MENU_YSZC,false),
       new ItemData($r('app.string.about_me'), $r('app.media.oh_about'),MainViewModel.MENU_ABOUT,false),
+      new ItemData($r('app.string.setting'), $r('app.media.setting'),MainViewModel.MENU_SETTING,false),
       // new ItemData($r('app.string.nor_setting'), $r('app.media.hm_gps'),MainViewModel.MENU_SETTING,false),
     ];
     return drawerGridData;

+ 13 - 9
oh_modules/.ohpm/lock.json5

@@ -62,6 +62,10 @@
         "@changwei/chardet": {
           "specifier": "^1.0.0",
           "version": "1.0.0"
+        },
+        "@tencent/wechat_open_sdk": {
+          "specifier": "1.0.0",
+          "version": "1.0.0"
         }
       },
       "devDependencies": {
@@ -309,6 +313,15 @@
       "dynamic": false,
       "maskedByOverrideDependencyMap": false
     },
+    "@tencent/wechat_open_sdk@1.0.0": {
+      "integrity": "sha512-rB1bWPTeMEir10+RguSlURf2ji/m7Xs0exh+EdRUEYhwKqnxMGylaASjX/A1nqZM1KBmx5+MVwt9DayTReP3mA==",
+      "storePath": "oh_modules/.ohpm/@tencent+wechat_open_sdk@1.0.0",
+      "dependencies": {},
+      "dynamicDependencies": {},
+      "dev": false,
+      "dynamic": false,
+      "maskedByOverrideDependencyMap": false
+    },
     "@ohos/hypium@1.0.19": {
       "integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==",
       "storePath": "oh_modules/.ohpm/@ohos+hypium@1.0.19",
@@ -418,15 +431,6 @@
       "dev": false,
       "dynamic": false,
       "maskedByOverrideDependencyMap": false
-    },
-    "@tencent/wechat_open_sdk@1.0.0": {
-      "integrity": "sha512-rB1bWPTeMEir10+RguSlURf2ji/m7Xs0exh+EdRUEYhwKqnxMGylaASjX/A1nqZM1KBmx5+MVwt9DayTReP3mA==",
-      "storePath": "oh_modules/.ohpm/@tencent+wechat_open_sdk@1.0.0",
-      "dependencies": {},
-      "dynamicDependencies": {},
-      "dev": false,
-      "dynamic": false,
-      "maskedByOverrideDependencyMap": false
     }
   }
 }

Неке датотеке нису приказане због велике количине промена