Forráskód Böngészése

修复列表点击播放

chendeben 1 éve
szülő
commit
cbd0b6c237

+ 5 - 28
entry/src/main/ets/common/widget/EnhancedFormUpdateService.ets

@@ -216,20 +216,6 @@ export class EnhancedFormUpdateService {
         await this.cleanupInvalidForms(prefs, validFormIds, results);
         await this.cleanupInvalidForms(prefs, validFormIds, results);
       }
       }
 
 
-      // 更新统计信息
-      this.updateStats.lastBatchStats = batchStats;
-      this.updateStats.totalUpdates += batchStats.total;
-      this.updateStats.successfulUpdates += batchStats.success;
-      this.updateStats.failedUpdates += batchStats.failed;
-
-      // 重新计算平均更新时间
-      if (this.updateStats.totalUpdates > 0) {
-        this.updateStats.averageUpdateTime = 
-          (this.updateStats.averageUpdateTime * (this.updateStats.totalUpdates - batchStats.total) + batchStats.averageUpdateTime * batchStats.total) / this.updateStats.totalUpdates;
-      }
-
-      
-
       return batchStats;
       return batchStats;
 
 
     } catch (error) {
     } catch (error) {
@@ -249,11 +235,11 @@ export class EnhancedFormUpdateService {
 
 
     for (let attempt = 0; attempt <= this.maxRetryCount; attempt++) {
     for (let attempt = 0; attempt <= this.maxRetryCount; attempt++) {
       try {
       try {
-        if (attempt > 0) {
-          const delay = this.retryDelays[Math.min(attempt - 1, this.retryDelays.length - 1)];
-          
-          await this.sleep(delay);
-        }
+        // if (attempt > 0) {
+        //   const delay = this.retryDelays[Math.min(attempt - 1, this.retryDelays.length - 1)];
+        //
+        //   await this.sleep(delay);
+        // }
 
 
         await this.updateSingleForm(formId, data, prefs);
         await this.updateSingleForm(formId, data, prefs);
         
         
@@ -432,15 +418,6 @@ export class EnhancedFormUpdateService {
           // 创建新的数据对象,包含处理后的图片信息
           // 创建新的数据对象,包含处理后的图片信息
           processedData.currentSong.coverImagePath = processedImageInfo.memoryUri;
           processedData.currentSong.coverImagePath = processedImageInfo.memoryUri;
           processedData.imageFileInfo = processedImageInfo as ImageFileInfo;
           processedData.imageFileInfo = processedImageInfo as ImageFileInfo;
-          // const processedData: WidgetData = {
-          //   ...data,
-          //   currentSong: {
-          //     ...data.currentSong,
-          //     coverImagePath: processedImageInfo.memoryUri // 使用 memory:// 格式
-          //   },
-          //   // 添加图片文件信息用于后续处理
-          //   imageFileInfo: processedImageInfo
-          // };
           
           
           hilog.info(0x0000, TAG, `📷 Local image processed successfully: ${processedImageInfo.fileName} -> ${processedImageInfo.memoryUri}`);
           hilog.info(0x0000, TAG, `📷 Local image processed successfully: ${processedImageInfo.fileName} -> ${processedImageInfo.memoryUri}`);
           return processedData;
           return processedData;

+ 1 - 3
entry/src/main/ets/common/widget/WidgetDataManager.ets

@@ -275,12 +275,10 @@ export class WidgetDataManager {
       showProgress: data.config.showProgress,
       showProgress: data.config.showProgress,
       showCover: data.config.showCover,
       showCover: data.config.showCover,
       widgetSize: data.config.size as string,
       widgetSize: data.config.size as string,
-      
+
       // 时间戳用于强制更新
       // 时间戳用于强制更新
       timestamp: Date.now()
       timestamp: Date.now()
     };
     };
-    
-    hilog.info(0x0000, TAG, `Formatted widget data: isPlaying=${formattedData.isPlaying}, hasNext=${formattedData.hasNext}, hasPrevious=${formattedData.hasPrevious}, title=${formattedData.songTitle}`);
     return formattedData;
     return formattedData;
   }
   }
 
 

+ 5 - 4
entry/src/main/ets/view/LocalMusic.ets

@@ -4765,9 +4765,10 @@ export struct LocalMusic {
         return
         return
         break;
         break;
       case CommonConstants.TYPE_LOCAL:
       case CommonConstants.TYPE_LOCAL:
-        if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
-          this.stop();
-        }
+        // 移除自动停止逻辑,让UnifiedPlayerService处理播放器状态管理
+        // if (this.CONTROL_PlayStatus !== PlayStatus.INIT) {
+        //   this.stop();
+        // }
 
 
         if (isFromSonPlayList) { //点击来自右下角的播放列表
         if (isFromSonPlayList) { //点击来自右下角的播放列表
           this.currentSong = item
           this.currentSong = item
@@ -4805,7 +4806,7 @@ export struct LocalMusic {
         this.name = this.currentSong.name
         this.name = this.currentSong.name
         this.cover = this.currentSong.pixelMapPath
         this.cover = this.currentSong.pixelMapPath
         this.artist = this.currentSong.artist
         this.artist = this.currentSong.artist
-        
+
         // 同步播放列表到UnifiedPlayerService
         // 同步播放列表到UnifiedPlayerService
         this.syncPlaylistToService();
         this.syncPlaylistToService();
         
         

+ 98 - 30
entry/src/main/ets/widget/pages/PlayerWidgetMedium.ets

@@ -43,30 +43,6 @@ struct PlayerWidgetMedium {
   @LocalStorageProp('imageColorHex') imageColorHex: string = '2A2A2A';
   @LocalStorageProp('imageColorHex') imageColorHex: string = '2A2A2A';
   @LocalStorageProp('imgName') imgName: string = ''; // 图片文件名,用于memory://协议
   @LocalStorageProp('imgName') imgName: string = ''; // 图片文件名,用于memory://协议
 
 
-  /**
-   * 获取按钮透明度
-   */
-  private getButtonOpacity(enabled: boolean): number {
-    return enabled ? 1.0 : 0.4;
-  }
-
-  /**
-   * 获取按钮颜色
-   */
-  private getButtonColor(enabled: boolean): string {
-    return enabled ? '#FF007DFF' : '#66000000';
-  }
-
-  /**
-   * 获取播放按钮图标
-   */
-  private getPlayButtonIcon(): Resource {
-    if (this.isLoading) {
-      return $r('app.media.hm_more'); // 加载状态图标
-    }
-    return this.isPlaying ? $r('app.media.hm_pause') : $r('app.media.hm_play');
-  }
-
   /**
   /**
    * 格式化歌曲标题显示
    * 格式化歌曲标题显示
    */
    */
@@ -95,9 +71,14 @@ struct PlayerWidgetMedium {
 
 
   /**
   /**
    * 生成渐变色
    * 生成渐变色
-   * 根据主色生成更丰富的渐变效果
+   * 根据封面图片的主色调生成合适的渐变背景
    */
    */
   private generateGradientColors(): [string, number][] {
   private generateGradientColors(): [string, number][] {
+    // 如果没有封面或颜色信息,使用默认渐变
+    if (!this.imageColorHex || this.imageColorHex.trim() === '' || this.imageColorHex === '2A2A2A') {
+      return this.getDefaultGradientColors();
+    }
+
     const baseColor = this.imageColorHex;
     const baseColor = this.imageColorHex;
     
     
     // 解析RGB值
     // 解析RGB值
@@ -105,6 +86,86 @@ struct PlayerWidgetMedium {
     const g = parseInt(baseColor.substring(2, 4), 16);
     const g = parseInt(baseColor.substring(2, 4), 16);
     const b = parseInt(baseColor.substring(4, 6), 16);
     const b = parseInt(baseColor.substring(4, 6), 16);
     
     
+    // 计算亮度,用于判断是深色还是浅色
+    const brightness = (r * 299 + g * 587 + b * 114) / 1000;
+    
+    // 根据亮度调整渐变策略
+    if (brightness < 60) {
+      // 深色封面:从更深的色调渐变到原色调
+      return this.generateDarkGradient(r, g, b);
+    } else if (brightness > 180) {
+      // 浅色封面:降低亮度,创建柔和渐变
+      return this.generateLightGradient(r, g, b);
+    } else {
+      // 中等亮度:标准渐变
+      return this.generateStandardGradient(r, g, b);
+    }
+  }
+
+  /**
+   * 生成深色渐变(适用于深色封面)
+   */
+  private generateDarkGradient(r: number, g: number, b: number): [string, number][] {
+    // 生成更深的起始色
+    const darkerR = Math.max(0, Math.floor(r * 0.2));
+    const darkerG = Math.max(0, Math.floor(g * 0.2));
+    const darkerB = Math.max(0, Math.floor(b * 0.2));
+    
+    // 中间色稍微提亮
+    const midR = Math.floor(r * 0.6);
+    const midG = Math.floor(g * 0.6);
+    const midB = Math.floor(b * 0.6);
+    
+    // 终点色适度提亮
+    const lightR = Math.min(255, Math.floor(r * 1.2));
+    const lightG = Math.min(255, Math.floor(g * 1.2));
+    const lightB = Math.min(255, Math.floor(b * 1.2));
+    
+    const darkerColor = `#ff${darkerR.toString(16).padStart(2, '0')}${darkerG.toString(16).padStart(2, '0')}${darkerB.toString(16).padStart(2, '0')}`;
+    const midColor = `#ff${midR.toString(16).padStart(2, '0')}${midG.toString(16).padStart(2, '0')}${midB.toString(16).padStart(2, '0')}`;
+    const lightColor = `#ff${lightR.toString(16).padStart(2, '0')}${lightG.toString(16).padStart(2, '0')}${lightB.toString(16).padStart(2, '0')}`;
+    
+    return [
+      [darkerColor, 0.0],
+      [midColor, 0.6],
+      [lightColor, 1.0]
+    ];
+  }
+
+  /**
+   * 生成浅色渐变(适用于浅色封面)
+   */
+  private generateLightGradient(r: number, g: number, b: number): [string, number][] {
+    // 大幅降低亮度作为起始色
+    const darkerR = Math.floor(r * 0.3);
+    const darkerG = Math.floor(g * 0.3);
+    const darkerB = Math.floor(b * 0.3);
+    
+    // 中间色适度降低亮度
+    const midR = Math.floor(r * 0.5);
+    const midG = Math.floor(g * 0.5);
+    const midB = Math.floor(b * 0.5);
+    
+    // 终点色保持相对较暗,避免过亮
+    const endR = Math.floor(r * 0.7);
+    const endG = Math.floor(g * 0.7);
+    const endB = Math.floor(b * 0.7);
+    
+    const darkerColor = `#ff${darkerR.toString(16).padStart(2, '0')}${darkerG.toString(16).padStart(2, '0')}${darkerB.toString(16).padStart(2, '0')}`;
+    const midColor = `#ff${midR.toString(16).padStart(2, '0')}${midG.toString(16).padStart(2, '0')}${midB.toString(16).padStart(2, '0')}`;
+    const endColor = `#ff${endR.toString(16).padStart(2, '0')}${endG.toString(16).padStart(2, '0')}${endB.toString(16).padStart(2, '0')}`;
+    
+    return [
+      [darkerColor, 0.0],
+      [midColor, 0.5],
+      [endColor, 1.0]
+    ];
+  }
+
+  /**
+   * 生成标准渐变(适用于中等亮度封面)
+   */
+  private generateStandardGradient(r: number, g: number, b: number): [string, number][] {
     // 生成较深的颜色作为渐变起始
     // 生成较深的颜色作为渐变起始
     const darkerR = Math.max(0, Math.floor(r * 0.4));
     const darkerR = Math.max(0, Math.floor(r * 0.4));
     const darkerG = Math.max(0, Math.floor(g * 0.4));
     const darkerG = Math.max(0, Math.floor(g * 0.4));
@@ -117,7 +178,7 @@ struct PlayerWidgetMedium {
     
     
     const darkerColor = `#ff${darkerR.toString(16).padStart(2, '0')}${darkerG.toString(16).padStart(2, '0')}${darkerB.toString(16).padStart(2, '0')}`;
     const darkerColor = `#ff${darkerR.toString(16).padStart(2, '0')}${darkerG.toString(16).padStart(2, '0')}${darkerB.toString(16).padStart(2, '0')}`;
     const midColor = `#ff${midR.toString(16).padStart(2, '0')}${midG.toString(16).padStart(2, '0')}${midB.toString(16).padStart(2, '0')}`;
     const midColor = `#ff${midR.toString(16).padStart(2, '0')}${midG.toString(16).padStart(2, '0')}${midB.toString(16).padStart(2, '0')}`;
-    const originalColor = `#ff${baseColor}`;
+    const originalColor = `#ff${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
     
     
     return [
     return [
       [darkerColor, 0.0],
       [darkerColor, 0.0],
@@ -126,6 +187,17 @@ struct PlayerWidgetMedium {
     ];
     ];
   }
   }
 
 
+  /**
+   * 获取默认渐变色(当没有封面时使用)
+   */
+  private getDefaultGradientColors(): [string, number][] {
+    return [
+      ['#ff1a1a1a', 0.0],  // 深灰色
+      ['#ff2a2a2a', 0.5],  // 中灰色
+      ['#ff3a3a3a', 1.0]   // 浅灰色
+    ];
+  }
+
   /**
   /**
    * 获取专辑封面
    * 获取专辑封面
    */
    */
@@ -192,7 +264,6 @@ struct PlayerWidgetMedium {
       .alignRules(MediumCoverAlignRules)
       .alignRules(MediumCoverAlignRules)
       .id('musicCover')
       .id('musicCover')
       .onClick(() => {
       .onClick(() => {
-        console.info('Heanup PlayerWidgetMedium: Album cover clicked');
         postCardAction(this, {
         postCardAction(this, {
           'action': 'router',
           'action': 'router',
           'abilityName': 'EntryAbility'
           'abilityName': 'EntryAbility'
@@ -211,7 +282,6 @@ struct PlayerWidgetMedium {
         .width(40)
         .width(40)
         .height(40)
         .height(40)
         .backgroundColor(Color.Transparent)
         .backgroundColor(Color.Transparent)
-        .enabled(!this.isLoading && this.hasPrevious)
         .opacity(this.hasPrevious ? 1.0 : 0.5)
         .opacity(this.hasPrevious ? 1.0 : 0.5)
         .onClick(() => {
         .onClick(() => {
           console.info(`Heanup PlayerWidgetMedium: Previous button clicked`);
           console.info(`Heanup PlayerWidgetMedium: Previous button clicked`);
@@ -238,7 +308,6 @@ struct PlayerWidgetMedium {
         .height(48)
         .height(48)
         .backgroundColor(Color.Transparent)
         .backgroundColor(Color.Transparent)
         .margin({ left: 20, right: 20 })
         .margin({ left: 20, right: 20 })
-        .enabled(!this.isLoading)
         .onClick(() => {
         .onClick(() => {
           console.info('Heanup PlayerWidgetMedium: Play/Pause button clicked');
           console.info('Heanup PlayerWidgetMedium: Play/Pause button clicked');
           if (!this.isLoading) {
           if (!this.isLoading) {
@@ -264,7 +333,6 @@ struct PlayerWidgetMedium {
         .width(40)
         .width(40)
         .height(40)
         .height(40)
         .backgroundColor(Color.Transparent)
         .backgroundColor(Color.Transparent)
-        .enabled(!this.isLoading && this.hasNext)
         .opacity(this.hasNext ? 1.0 : 0.5)
         .opacity(this.hasNext ? 1.0 : 0.5)
         .onClick(() => {
         .onClick(() => {
           console.info(`Heanup PlayerWidgetMedium: Next button clicked`);
           console.info(`Heanup PlayerWidgetMedium: Next button clicked`);

+ 0 - 3
entry/src/main/ets/widget/pages/PlayerWidgetSmall.ets

@@ -27,7 +27,6 @@ struct PlayerWidgetSmall {
       .width(36)
       .width(36)
       .height(36)
       .height(36)
       .backgroundColor(Color.Transparent)
       .backgroundColor(Color.Transparent)
-      .enabled(!this.isLoading && this.hasPrevious)
       .opacity(this.hasPrevious ? 1.0 : 0.5)
       .opacity(this.hasPrevious ? 1.0 : 0.5)
       .onClick(() => {
       .onClick(() => {
         console.info(`Heanup PlayerWidgetSmall: Previous button clicked`);
         console.info(`Heanup PlayerWidgetSmall: Previous button clicked`);
@@ -54,7 +53,6 @@ struct PlayerWidgetSmall {
       .height(44)
       .height(44)
       .backgroundColor(Color.Transparent)
       .backgroundColor(Color.Transparent)
       .margin({ left: 8, right: 8 })
       .margin({ left: 8, right: 8 })
-      .enabled(!this.isLoading)
       .onClick(() => {
       .onClick(() => {
         console.info('Heanup PlayerWidgetSmall: Play/Pause button clicked');
         console.info('Heanup PlayerWidgetSmall: Play/Pause button clicked');
         if (!this.isLoading) {
         if (!this.isLoading) {
@@ -80,7 +78,6 @@ struct PlayerWidgetSmall {
       .width(36)
       .width(36)
       .height(36)
       .height(36)
       .backgroundColor(Color.Transparent)
       .backgroundColor(Color.Transparent)
-      .enabled(!this.isLoading && this.hasNext)
       .opacity(this.hasNext ? 1.0 : 0.5)
       .opacity(this.hasNext ? 1.0 : 0.5)
       .onClick(() => {
       .onClick(() => {
         console.info(`Heanup PlayerWidgetSmall: Next button clicked`);
         console.info(`Heanup PlayerWidgetSmall: Next button clicked`);

+ 0 - 1
entry/src/main/ets/widget/pages/PlayerWidgetSquare.ets

@@ -136,7 +136,6 @@ struct PlayerWidgetSquare {
         .symbolEffect(new ReplaceSymbolEffect(EffectScope.WHOLE), true)
         .symbolEffect(new ReplaceSymbolEffect(EffectScope.WHOLE), true)
         .fontColor(['#E5FFFFFF'])
         .fontColor(['#E5FFFFFF'])
         .alignRules(PlayAlignRules)
         .alignRules(PlayAlignRules)
-        .enabled(!this.isLoading)
         .onClick(() => {
         .onClick(() => {
           console.info('Heanup PlayerWidgetSquare: Play/Pause button clicked');
           console.info('Heanup PlayerWidgetSquare: Play/Pause button clicked');
           if (!this.isLoading) {
           if (!this.isLoading) {