|
|
@@ -32,7 +32,7 @@ export class FormLayoutManager {
|
|
|
* @returns 适配后的格式化数据
|
|
|
*/
|
|
|
public adaptDataForSize(widgetData: WidgetData, size: WidgetSize): FormattedWidgetData {
|
|
|
- hilog.info(0x0000, TAG, `Adapting data for size: ${size}`);
|
|
|
+ hilog.info(0x0000, TAG, `Adapting data for size: ${size}, coverImagePath: ${widgetData.currentSong.coverImagePath}`);
|
|
|
|
|
|
const baseData = this.formatBaseData(widgetData);
|
|
|
|
|
|
@@ -49,6 +49,127 @@ export class FormLayoutManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 格式化基础数据
|
|
|
+ */
|
|
|
+ private formatBaseData(data: WidgetData): FormattedWidgetData {
|
|
|
+ hilog.info(0x0000, TAG, `Formatting base data: coverImagePath=${data.currentSong.coverImagePath}`);
|
|
|
+
|
|
|
+ return {
|
|
|
+ // 播放状态
|
|
|
+ isPlaying: data.playState.isPlaying,
|
|
|
+ isPaused: data.playState.isPaused,
|
|
|
+ isLoading: data.playState.isLoading,
|
|
|
+
|
|
|
+ // 歌曲信息
|
|
|
+ songTitle: this.truncateText(data.currentSong.title, 30),
|
|
|
+ songArtist: this.truncateText(data.currentSong.artist, 20),
|
|
|
+ songAlbum: this.truncateText(data.currentSong.album, 20),
|
|
|
+ coverImage: data.currentSong.coverImagePath || '',
|
|
|
+
|
|
|
+ // 播放进度
|
|
|
+ currentTime: data.progress.currentTimeText,
|
|
|
+ totalTime: data.progress.totalTimeText,
|
|
|
+ progressPercentage: data.progress.percentage,
|
|
|
+
|
|
|
+ // 控制按钮状态
|
|
|
+ hasNext: data.playlist.hasNext,
|
|
|
+ hasPrevious: data.playlist.hasPrevious,
|
|
|
+
|
|
|
+ // 卡片配置
|
|
|
+ showProgress: data.config.showProgress,
|
|
|
+ showCover: data.config.showCover,
|
|
|
+ widgetSize: data.config.size as string,
|
|
|
+
|
|
|
+ // 时间戳用于强制更新
|
|
|
+ timestamp: Date.now()
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 适配小尺寸卡片
|
|
|
+ */
|
|
|
+ private adaptForSmallWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
+ return {
|
|
|
+ isPlaying: baseData.isPlaying,
|
|
|
+ isPaused: baseData.isPaused,
|
|
|
+ isLoading: baseData.isLoading,
|
|
|
+ songTitle: this.truncateText(widgetData.currentSong.title, 15),
|
|
|
+ songArtist: this.truncateText(widgetData.currentSong.artist, 12),
|
|
|
+ songAlbum: baseData.songAlbum,
|
|
|
+ coverImage: baseData.coverImage,
|
|
|
+ currentTime: baseData.currentTime,
|
|
|
+ totalTime: baseData.totalTime,
|
|
|
+ progressPercentage: baseData.progressPercentage,
|
|
|
+ hasNext: baseData.hasNext,
|
|
|
+ hasPrevious: baseData.hasPrevious,
|
|
|
+ showProgress: false,
|
|
|
+ showCover: false,
|
|
|
+ widgetSize: baseData.widgetSize,
|
|
|
+ timestamp: baseData.timestamp
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 适配中等尺寸卡片
|
|
|
+ */
|
|
|
+ private adaptForMediumWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
+ hilog.info(0x0000, TAG, `Adapting for medium widget: coverImage=${baseData.coverImage}`);
|
|
|
+
|
|
|
+ return {
|
|
|
+ isPlaying: baseData.isPlaying,
|
|
|
+ isPaused: baseData.isPaused,
|
|
|
+ isLoading: baseData.isLoading,
|
|
|
+ songTitle: this.truncateText(widgetData.currentSong.title, 25),
|
|
|
+ songArtist: this.truncateText(widgetData.currentSong.artist, 18),
|
|
|
+ songAlbum: baseData.songAlbum,
|
|
|
+ coverImage: widgetData.currentSong.coverImagePath || '', // 确保coverImage被正确传递
|
|
|
+ currentTime: baseData.currentTime,
|
|
|
+ totalTime: baseData.totalTime,
|
|
|
+ progressPercentage: baseData.progressPercentage,
|
|
|
+ hasNext: baseData.hasNext,
|
|
|
+ hasPrevious: baseData.hasPrevious,
|
|
|
+ showProgress: false,
|
|
|
+ showCover: true,
|
|
|
+ widgetSize: baseData.widgetSize,
|
|
|
+ timestamp: baseData.timestamp
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 适配大尺寸卡片
|
|
|
+ */
|
|
|
+ private adaptForLargeWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
+ return {
|
|
|
+ isPlaying: baseData.isPlaying,
|
|
|
+ isPaused: baseData.isPaused,
|
|
|
+ isLoading: baseData.isLoading,
|
|
|
+ songTitle: this.truncateText(widgetData.currentSong.title, 35),
|
|
|
+ songArtist: this.truncateText(widgetData.currentSong.artist, 25),
|
|
|
+ songAlbum: baseData.songAlbum,
|
|
|
+ coverImage: baseData.coverImage,
|
|
|
+ currentTime: baseData.currentTime,
|
|
|
+ totalTime: baseData.totalTime,
|
|
|
+ progressPercentage: baseData.progressPercentage,
|
|
|
+ hasNext: baseData.hasNext,
|
|
|
+ hasPrevious: baseData.hasPrevious,
|
|
|
+ showProgress: true,
|
|
|
+ showCover: true,
|
|
|
+ widgetSize: baseData.widgetSize,
|
|
|
+ timestamp: baseData.timestamp
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 截断文本
|
|
|
+ */
|
|
|
+ private truncateText(text: string, maxLength: number): string {
|
|
|
+ if (!text || text.length <= maxLength) {
|
|
|
+ return text || '';
|
|
|
+ }
|
|
|
+ return text.substring(0, maxLength - 1) + '…';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取卡片尺寸对应的页面路径
|
|
|
* @param size 卡片尺寸
|
|
|
@@ -95,29 +216,26 @@ export class FormLayoutManager {
|
|
|
|
|
|
switch (size) {
|
|
|
case WidgetSize.SMALL:
|
|
|
- const smallConfig: WidgetConfig = {
|
|
|
+ return {
|
|
|
size: baseConfig.size,
|
|
|
theme: baseConfig.theme,
|
|
|
showProgress: false,
|
|
|
showCover: false
|
|
|
};
|
|
|
- return smallConfig;
|
|
|
case WidgetSize.MEDIUM:
|
|
|
- const mediumConfig: WidgetConfig = {
|
|
|
+ return {
|
|
|
size: baseConfig.size,
|
|
|
theme: baseConfig.theme,
|
|
|
- showProgress: true,
|
|
|
- showCover: false
|
|
|
+ showProgress: false,
|
|
|
+ showCover: true
|
|
|
};
|
|
|
- return mediumConfig;
|
|
|
case WidgetSize.LARGE:
|
|
|
- const largeConfig: WidgetConfig = {
|
|
|
+ return {
|
|
|
size: baseConfig.size,
|
|
|
theme: baseConfig.theme,
|
|
|
showProgress: true,
|
|
|
showCover: true
|
|
|
};
|
|
|
- return largeConfig;
|
|
|
default:
|
|
|
return baseConfig;
|
|
|
}
|
|
|
@@ -230,113 +348,4 @@ export class FormLayoutManager {
|
|
|
return this.getResponsiveLayoutParams(WidgetSize.MEDIUM);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 格式化基础数据
|
|
|
- */
|
|
|
- private formatBaseData(widgetData: WidgetData): FormattedWidgetData {
|
|
|
- return {
|
|
|
- isPlaying: widgetData.playState.isPlaying,
|
|
|
- isPaused: widgetData.playState.isPaused,
|
|
|
- isLoading: widgetData.playState.isLoading,
|
|
|
- songTitle: widgetData.currentSong.title || '暂无播放',
|
|
|
- songArtist: widgetData.currentSong.artist || '未知艺术家',
|
|
|
- songAlbum: widgetData.currentSong.album || '未知专辑',
|
|
|
- coverImage: widgetData.currentSong.coverImagePath || '',
|
|
|
- currentTime: widgetData.progress.currentTimeText || '00:00',
|
|
|
- totalTime: widgetData.progress.totalTimeText || '00:00',
|
|
|
- progressPercentage: widgetData.progress.percentage || 0,
|
|
|
- hasNext: widgetData.playlist.hasNext,
|
|
|
- hasPrevious: widgetData.playlist.hasPrevious,
|
|
|
- showProgress: widgetData.config.showProgress,
|
|
|
- showCover: widgetData.config.showCover,
|
|
|
- widgetSize: widgetData.config.size.toString(),
|
|
|
- timestamp: Date.now()
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 适配小尺寸卡片数据
|
|
|
- */
|
|
|
- private adaptForSmallWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
- const result: FormattedWidgetData = {
|
|
|
- isPlaying: baseData.isPlaying,
|
|
|
- isPaused: baseData.isPaused,
|
|
|
- isLoading: baseData.isLoading,
|
|
|
- songTitle: this.truncateText(baseData.songTitle, 20), // 小卡片只显示歌曲标题,如果标题过长则截断
|
|
|
- songArtist: baseData.songArtist,
|
|
|
- songAlbum: baseData.songAlbum,
|
|
|
- coverImage: baseData.coverImage,
|
|
|
- currentTime: baseData.currentTime,
|
|
|
- totalTime: baseData.totalTime,
|
|
|
- progressPercentage: baseData.progressPercentage,
|
|
|
- hasNext: baseData.hasNext,
|
|
|
- hasPrevious: baseData.hasPrevious,
|
|
|
- showProgress: false,
|
|
|
- showCover: false,
|
|
|
- widgetSize: WidgetSize.SMALL,
|
|
|
- timestamp: baseData.timestamp
|
|
|
- };
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 适配中等尺寸卡片数据
|
|
|
- */
|
|
|
- private adaptForMediumWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
- const result: FormattedWidgetData = {
|
|
|
- isPlaying: baseData.isPlaying,
|
|
|
- isPaused: baseData.isPaused,
|
|
|
- isLoading: baseData.isLoading,
|
|
|
- songTitle: this.truncateText(baseData.songTitle, 30), // 中等卡片显示更多信息,但仍需要适当截断
|
|
|
- songArtist: this.truncateText(baseData.songArtist, 25),
|
|
|
- songAlbum: this.truncateText(baseData.songAlbum, 25),
|
|
|
- coverImage: baseData.coverImage,
|
|
|
- currentTime: baseData.currentTime,
|
|
|
- totalTime: baseData.totalTime,
|
|
|
- progressPercentage: baseData.progressPercentage,
|
|
|
- hasNext: baseData.hasNext,
|
|
|
- hasPrevious: baseData.hasPrevious,
|
|
|
- showProgress: true,
|
|
|
- showCover: false,
|
|
|
- widgetSize: WidgetSize.MEDIUM,
|
|
|
- timestamp: baseData.timestamp
|
|
|
- };
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 适配大尺寸卡片数据
|
|
|
- */
|
|
|
- private adaptForLargeWidget(baseData: FormattedWidgetData, widgetData: WidgetData): FormattedWidgetData {
|
|
|
- const result: FormattedWidgetData = {
|
|
|
- isPlaying: baseData.isPlaying,
|
|
|
- isPaused: baseData.isPaused,
|
|
|
- isLoading: baseData.isLoading,
|
|
|
- songTitle: this.truncateText(baseData.songTitle, 40), // 大卡片可以显示完整信息
|
|
|
- songArtist: this.truncateText(baseData.songArtist, 35),
|
|
|
- songAlbum: this.truncateText(baseData.songAlbum, 35),
|
|
|
- coverImage: baseData.coverImage,
|
|
|
- currentTime: baseData.currentTime,
|
|
|
- totalTime: baseData.totalTime,
|
|
|
- progressPercentage: baseData.progressPercentage,
|
|
|
- hasNext: baseData.hasNext,
|
|
|
- hasPrevious: baseData.hasPrevious,
|
|
|
- showProgress: true,
|
|
|
- showCover: true,
|
|
|
- widgetSize: WidgetSize.LARGE,
|
|
|
- timestamp: baseData.timestamp
|
|
|
- };
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 截断文本
|
|
|
- */
|
|
|
- private truncateText(text: string, maxLength: number): string {
|
|
|
- if (!text || text.length <= maxLength) {
|
|
|
- return text;
|
|
|
- }
|
|
|
- return text.substring(0, maxLength - 3) + '...';
|
|
|
- }
|
|
|
}
|