Sfoglia il codice sorgente

设置页增加封面及歌词API设置

chendeben 1 anno fa
parent
commit
624e47909b

+ 5 - 3
entry/src/main/ets/common/util/NetAxiosUtil.ets

@@ -15,7 +15,8 @@ class NetAxiosUtil{
     if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
     if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
       artist = ''
       artist = ''
     }
     }
-    let requestUrl = PreferencesUtil.getStringSync('LRC_API')
+    let baseUrl = PreferencesUtil.getStringSync('LRC_API')||CommonConstants.LRC_API
+    let requestUrl = baseUrl
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 
 
     LogUtil.debug("Heanup requestUrl =" + requestUrl + '; title = '+title+'; artist = '+artist)
     LogUtil.debug("Heanup requestUrl =" + requestUrl + '; title = '+title+'; artist = '+artist)
@@ -63,7 +64,8 @@ class NetAxiosUtil{
 
 
 
 
   async getLyricCover(title: string, artist: string): Promise<string> {
   async getLyricCover(title: string, artist: string): Promise<string> {
-    const cover_url = CommonConstants.COVER_API
+    let baseUrl = PreferencesUtil.getStringSync('COVER_API')||CommonConstants.COVER_API
+    const cover_url = baseUrl
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 
 
     try {
     try {
@@ -73,7 +75,7 @@ class NetAxiosUtil{
         readTimeout: 60000,
         readTimeout: 60000,
         connectTimeout: 60000,
         connectTimeout: 60000,
       };
       };
-
+      LogUtil.debug("Heanup 请求封面URL: " + cover_url);
       const response: http.HttpResponse = await httpRequest.request(cover_url, options);
       const response: http.HttpResponse = await httpRequest.request(cover_url, options);
       if (response.responseCode === 200) {
       if (response.responseCode === 200) {
         const res = response.result as string;
         const res = response.result as string;

+ 60 - 13
entry/src/main/ets/pages/SettingPage.ets

@@ -20,6 +20,10 @@ export struct SettingPage {
   @State isMediacodec: boolean = false //是否启用硬件解码
   @State isMediacodec: boolean = false //是否启用硬件解码
   @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
   @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
   @State isMusicBGCover: boolean = true //播放背景随封面
   @State isMusicBGCover: boolean = true //播放背景随封面
+  @State showCoverApiDialog: boolean = false
+  @State tempCoverApiUrl: string = ''
+  @State coverApiUrl: string = PreferencesUtil.getStringSync('COVER_API', 'https://lrc.ss5.xyz/cover')
+  @State apiDialogType: 'lyric' | 'cover' = 'lyric'
   static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
   static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
   static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
   static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
   static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
   static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
@@ -44,7 +48,7 @@ export struct SettingPage {
 
 
   apiDialogController: CustomDialogController = new CustomDialogController({
   apiDialogController: CustomDialogController = new CustomDialogController({
     builder: CustomContentDialog({
     builder: CustomContentDialog({
-      primaryTitle: '修改歌词API地址',
+      primaryTitle: this.apiDialogType === 'lyric' ? '修改歌词API地址' : '修改封面API地址',
       contentBuilder: () => {
       contentBuilder: () => {
         this.buildApiDialogContent();
         this.buildApiDialogContent();
       },
       },
@@ -58,15 +62,26 @@ export struct SettingPage {
         {
         {
           value: '保存',
           value: '保存',
           action: () => {
           action: () => {
-            this.lyricApiUrl = this.tempApiUrl
-            PreferencesUtil.put('LRC_API', this.lyricApiUrl)
+            if (this.apiDialogType === 'lyric') {
+              this.lyricApiUrl = this.tempApiUrl
+              PreferencesUtil.put('LRC_API', this.lyricApiUrl)
+              this.getUIContext().getPromptAction().showToast({
+                message: '保存成功,当前LRC_API:' + this.lyricApiUrl,
+                duration: 2000,
+                showMode: promptAction.ToastShowMode.TOP_MOST,
+                bottom: 85
+              })
+            } else {
+              this.coverApiUrl = this.tempApiUrl
+              PreferencesUtil.put('COVER_API', this.coverApiUrl)
+              this.getUIContext().getPromptAction().showToast({
+                message: '保存成功,当前COVER_API:' + this.coverApiUrl,
+                duration: 2000,
+                showMode: promptAction.ToastShowMode.TOP_MOST,
+                bottom: 85
+              })
+            }
             this.apiDialogController.close();
             this.apiDialogController.close();
-            this.getUIContext().getPromptAction().showToast({
-              message: '保存成功,当前LRC_API:' + this.lyricApiUrl,
-              duration: 2000,
-              showMode: promptAction.ToastShowMode.TOP_MOST,
-              bottom: 85
-            })
           }
           }
         }
         }
       ]
       ]
@@ -78,7 +93,7 @@ export struct SettingPage {
   @Builder
   @Builder
   buildApiDialogContent() {
   buildApiDialogContent() {
     Column() {
     Column() {
-      TextInput({ text: this.tempApiUrl, placeholder: '请输入API地址' })
+      TextInput({ text: this.tempApiUrl, placeholder: this.apiDialogType === 'lyric' ? '请输入歌词API地址' : '请输入封面API地址' })
         .onChange((val: string) => {
         .onChange((val: string) => {
           this.tempApiUrl = val
           this.tempApiUrl = val
         })
         })
@@ -176,9 +191,9 @@ export struct SettingPage {
 
 
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
 
-        //第三方歌词API设置
+        // API设置(合并标题)
         Row() {
         Row() {
-          Text('第三方歌词API设置')
+          Text('API设置')
             .margin({ left: 38, right: 20 })
             .margin({ left: 38, right: 20 })
             .fontSize(16)
             .fontSize(16)
             .fontColor(Color.Gray)
             .fontColor(Color.Gray)
@@ -188,9 +203,14 @@ export struct SettingPage {
         .height(55)
         .height(55)
 
 
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+        // 歌词API地址展示
         Row() {
         Row() {
+          Text('歌词:')
+            .margin({ left: 38, right: 6 })
+            .fontSize(15)
+            .fontColor(Color.Gray)
           Text(this.lyricApiUrl)
           Text(this.lyricApiUrl)
-            .margin({ left: 38, right: 10 })
+            .margin({ right: 10 })
             .fontSize(15)
             .fontSize(15)
             .fontColor(Color.Gray)
             .fontColor(Color.Gray)
             .layoutWeight(1)
             .layoutWeight(1)
@@ -200,6 +220,7 @@ export struct SettingPage {
             .height(28)
             .height(28)
             .margin({ right: 18 })
             .margin({ right: 18 })
             .onClick(() => {
             .onClick(() => {
+              this.apiDialogType = 'lyric'
               this.tempApiUrl = this.lyricApiUrl
               this.tempApiUrl = this.lyricApiUrl
               this.apiDialogController.open()
               this.apiDialogController.open()
             })
             })
@@ -208,6 +229,32 @@ export struct SettingPage {
         .width('100%')
         .width('100%')
         .margin({ top: 8, bottom: 12 })
         .margin({ top: 8, bottom: 12 })
 
 
+        // 封面API地址展示
+        Row() {
+          Text('封面:')
+            .margin({ left: 38, right: 6 })
+            .fontSize(15)
+            .fontColor(Color.Gray)
+          Text(this.coverApiUrl)
+            .margin({ right: 10 })
+            .fontSize(15)
+            .fontColor(Color.Gray)
+            .layoutWeight(1)
+          // 编辑图标按钮
+          Image($r('app.media.edit'))
+            .width(28)
+            .height(28)
+            .margin({ right: 18 })
+            .onClick(() => {
+              this.apiDialogType = 'cover'
+              this.tempApiUrl = this.coverApiUrl
+              this.apiDialogController.open()
+            })
+          Blank()
+        }
+        .width('100%')
+        .margin({ top: 8, bottom: 12 })
+
       }
       }
       .backgroundColor(Color.White)
       .backgroundColor(Color.White)
       .margin({
       .margin({