Explorar el Código

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	entry/src/main/ets/pages/SettingPage.ets
onecold hace 1 año
padre
commit
2f53584701

+ 36 - 0
entry/src/main/ets/MyAbilityStage.ets

@@ -0,0 +1,36 @@
+import AbilityStage from '@ohos.app.ability.AbilityStage';
+import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
+import dataStorage from '@ohos.data.storage';
+import hilog from '@ohos.hilog';
+
+export default class MyAbilityStage extends AbilityStage {
+  private storage: dataStorage.Storage | undefined = undefined;
+
+  async onCreate(): Promise<void> {
+    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
+    try {
+      // 获取存储实例
+      this.storage = await dataStorage.getStorage(this.context.cacheDir);
+      // 保存当前颜色模式
+      if (this.storage) {
+        await this.storage.put('currentColorMode', this.context.config.colorMode);
+        await this.storage.flush();
+      }
+    } catch (err) {
+      hilog.error(0x0000, 'testTag', 'Failed to initialize storage: %{public}s', err.message);
+    }
+  }
+
+  async onConfigurationUpdate(newConfig: import('@ohos.app.ability.Configuration').Configuration): Promise<void> {
+    try {
+      if (this.storage) {
+        // 更新颜色模式
+        await this.storage.put('currentColorMode', newConfig.colorMode);
+        await this.storage.flush();
+        hilog.info(0x0000, 'testTag', 'the newConfig.colorMode is %{public}s', JSON.stringify(newConfig.colorMode) ?? '');
+      }
+    } catch (err) {
+      hilog.error(0x0000, 'testTag', 'Failed to update color mode: %{public}s', err.message);
+    }
+  }
+} 

+ 10 - 2
entry/src/main/ets/common/util/NetAxiosUtil.ets

@@ -15,7 +15,11 @@ class NetAxiosUtil{
     if(StrUtil.isNotEmpty(title)&&title==='全世界最好的你'){
       artist = ''
     }
-    let baseUrl = PreferencesUtil.getStringSync('LRC_API')||CommonConstants.LRC_API
+    let baseUrl = PreferencesUtil.getStringSync('LRC_API')
+    if (baseUrl=='') {
+      LogUtil.debug("Heanup 未设置API");
+      return ''
+    }
     let requestUrl = baseUrl
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 
@@ -64,7 +68,11 @@ class NetAxiosUtil{
 
 
   async getLyricCover(title: string, artist: string): Promise<string> {
-    let baseUrl = PreferencesUtil.getStringSync('COVER_API')||CommonConstants.COVER_API
+    let baseUrl = PreferencesUtil.getStringSync('COVER_API')
+    if (baseUrl=='') {
+      LogUtil.debug("Heanup 未设置API");
+      return ''
+    }
     const cover_url = baseUrl
       + '?title=' + encodeURIComponent(title.trim()) + '&artist=' + encodeURIComponent(artist.trim());
 

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

@@ -20,13 +20,10 @@ export struct SettingPage {
   @State isMediacodec: boolean = false //是否启用硬件解码
   @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
   @State isMusicBGCover: boolean = true //播放背景随封面
-  @State sortType: number = 4 //默认排序方式
   @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 SORT_TYPE: string = 'musicSortType';
   static readonly IS_BGPLAY_OPEN: string = 'isBgPlayOpen';
   static readonly IS_AUTO_RATATE: string = 'isAutoRatate';
   static readonly iS_MEMORY_PLAY: string = 'isMemoryPlay';
@@ -108,7 +105,6 @@ export struct SettingPage {
 
   // 组件生命周期
   aboutToAppear() {
-    this.sortType  = PreferencesUtil.getNumberSync(SettingPage.SORT_TYPE, 4)
     this.isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
     this.isAutoRatate = PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_RATATE, true)
     this.isMemoryPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_PLAY, true)
@@ -165,44 +161,6 @@ export struct SettingPage {
         .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 })
-            .fontSize(15)
-            .fontColor(Color.Gray)
-            .fontWeight(480)
-          Blank()
-          Select([//默认排序模式
-            { value: CommonConstants.SORT_ARRAY[0] },
-            { value: CommonConstants.SORT_ARRAY[1] },
-            { value: CommonConstants.SORT_ARRAY[2] },
-            { value: CommonConstants.SORT_ARRAY[3] },
-            { value: CommonConstants.SORT_ARRAY[4] },
-            { value: CommonConstants.SORT_ARRAY[5] },
-            { value: CommonConstants.SORT_ARRAY[6] },
-            { value: CommonConstants.SORT_ARRAY[7] }])
-            .font({ size: 15, weight: FontWeight.Medium })
-            .fontColor(Color.Gray)
-            .margin({right:28})
-            .selected(this.sortType)
-            .value(CommonConstants.SORT_ARRAY[this.sortType])
-            .onSelect(async (_index: number, text?: string | undefined) => {
-              this.sortType = _index
-              PreferencesUtil.put(SettingPage.SORT_TYPE, this.sortType)
-            })
-
-
-        }
-        .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'))
@@ -231,7 +189,6 @@ export struct SettingPage {
         .width('100%')
         .height(55)
 
-
         Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
         // API设置(合并标题)

+ 29 - 1
entry/src/main/ets/pages/index.ets

@@ -14,10 +14,38 @@
  */
 
 import router from '@ohos.router'
+import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
+import dataStorage from '@ohos.data.storage';
+import common from '@ohos.app.ability.common';
 
 @Entry
 @Component
 struct indexPage {
+  @State currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
+  private storage: dataStorage.Storage | undefined = undefined;
+
+  async aboutToAppear() {
+    try {
+      const context = getContext(this) as common.UIAbilityContext;
+      this.storage = await dataStorage.getStorage(context.cacheDir);
+      if (this.storage) {
+        const colorMode = await this.storage.get('currentColorMode', this.currentMode);
+        this.currentMode = colorMode as number;
+        this.updateUI();
+      }
+    } catch (err) {
+      console.error('Failed to get color mode:', err);
+    }
+  }
+
+  updateUI() {
+    if (this.currentMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
+      console.info('当前为浅色模式');
+    } else {
+      console.info('当前为深色模式');
+    }
+  }
+
   build() {
     Column() {
       Button($r('app.string.video_demo'))
@@ -34,7 +62,7 @@ struct indexPage {
     }
     .width('100%')
     .height('100%')
-    .backgroundColor(Color.Gray)
+    .backgroundColor(this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT ? Color.Gray : '#121212')
     .justifyContent(FlexAlign.Center)
   }
 }

+ 108 - 0
entry/src/main/resources/dark/element/color.json

@@ -0,0 +1,108 @@
+{
+  "color": [
+    {
+      "name": "start_window_background",
+      "value": "#121212"
+    },
+    {
+      "name": "silvery",
+      "value": "#1E1E1E"
+    },
+    {
+      "name": "white",
+      "value": "#FFFFFF"
+    },
+    {
+      "name": "touming",
+      "value": "#00FFFFFF"
+    },
+    {
+      "name": "ban_touming",
+      "value": "#00000000"
+    },
+    {
+      "name": "title_bar_bg",
+      "value": "#FF4081"
+    },
+    {
+      "name": "index_background",
+      "value": "#121212"
+    },
+    {
+      "name": "tab_bar_sel",
+      "value": "#55ceac"
+    },
+    {
+      "name": "tab_bar_normal",
+      "value": "#2C2C2C"
+    },
+    {
+      "name": "index_tab_font_color",
+      "value": "#FFFFFF"
+    },
+    {
+      "name": "index_tab_selected_font_color",
+      "value": "#007DFF"
+    },
+    {
+      "name": "index_tab_unselected_font_color",
+      "value": "#666666"
+    },
+    {
+      "name": "index_tab_local_list_font_color",
+      "value": "#999999"
+    },
+    {
+      "name": "divider_color",
+      "value": "#333333"
+    },
+    {
+      "name": "button_back_ground_color",
+      "value": "#007DFF"
+    },
+    {
+      "name": "dodgerBlue",
+      "value": "#1E90FF"
+    },
+    {
+      "name": "RoyalBlue",
+      "value": "#4169E1"
+    },
+    {
+      "name": "track_color",
+      "value": "#333333"
+    },
+    {
+      "name": "speed_text_color",
+      "value": "#999999"
+    },
+    {
+      "name": "btn_green",
+      "value": "#55ceac"
+    },
+    {
+      "name": "pri_bg",
+      "value": "#1E1E1E"
+    },
+    {
+      "name": "orange",
+      "value": "#FF8C00"
+    },
+    {
+      "name": "line_blue",
+      "value": "#00cccc"
+    },
+    {
+      "name": "btn_red",
+      "value": "#ff6b47"
+    },
+    {
+      "name": "slider_track",
+      "value": "#33FFFFFF"
+    },
+    {
+      "name": "select_swiper",
+      "value": "#DBFFFFFF"
+    }
+  ]
+}