|
@@ -33,55 +33,21 @@ export interface MusicCardLyricLines {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class MusicCardBindingData {
|
|
export class MusicCardBindingData {
|
|
|
- title: string
|
|
|
|
|
- artist: string
|
|
|
|
|
- coverPath: string
|
|
|
|
|
- hasCoverImage: boolean
|
|
|
|
|
- hasSong: boolean
|
|
|
|
|
- isPlaying: boolean
|
|
|
|
|
- currentPositionMs: number
|
|
|
|
|
- durationMs: number
|
|
|
|
|
- currentTimeText: string
|
|
|
|
|
- durationTimeText: string
|
|
|
|
|
- lyricLine1: string
|
|
|
|
|
- lyricLine2: string
|
|
|
|
|
- hasLyric: boolean
|
|
|
|
|
- filePath: string
|
|
|
|
|
- updatedAtMs: number
|
|
|
|
|
-
|
|
|
|
|
- constructor(
|
|
|
|
|
- title: string,
|
|
|
|
|
- artist: string,
|
|
|
|
|
- coverPath: string,
|
|
|
|
|
- hasCoverImage: boolean,
|
|
|
|
|
- hasSong: boolean,
|
|
|
|
|
- isPlaying: boolean,
|
|
|
|
|
- currentPositionMs: number,
|
|
|
|
|
- durationMs: number,
|
|
|
|
|
- currentTimeText: string,
|
|
|
|
|
- durationTimeText: string,
|
|
|
|
|
- lyricLine1: string,
|
|
|
|
|
- lyricLine2: string,
|
|
|
|
|
- hasLyric: boolean,
|
|
|
|
|
- filePath: string,
|
|
|
|
|
- updatedAtMs: number
|
|
|
|
|
- ) {
|
|
|
|
|
- this.title = title
|
|
|
|
|
- this.artist = artist
|
|
|
|
|
- this.coverPath = coverPath
|
|
|
|
|
- this.hasCoverImage = hasCoverImage
|
|
|
|
|
- this.hasSong = hasSong
|
|
|
|
|
- this.isPlaying = isPlaying
|
|
|
|
|
- this.currentPositionMs = currentPositionMs
|
|
|
|
|
- this.durationMs = durationMs
|
|
|
|
|
- this.currentTimeText = currentTimeText
|
|
|
|
|
- this.durationTimeText = durationTimeText
|
|
|
|
|
- this.lyricLine1 = lyricLine1
|
|
|
|
|
- this.lyricLine2 = lyricLine2
|
|
|
|
|
- this.hasLyric = hasLyric
|
|
|
|
|
- this.filePath = filePath
|
|
|
|
|
- this.updatedAtMs = updatedAtMs
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ title: string = MUSIC_CARD_EMPTY_TITLE
|
|
|
|
|
+ artist: string = MUSIC_CARD_EMPTY_ARTIST
|
|
|
|
|
+ coverPath: string = ''
|
|
|
|
|
+ hasCoverImage: boolean = false
|
|
|
|
|
+ hasSong: boolean = false
|
|
|
|
|
+ isPlaying: boolean = false
|
|
|
|
|
+ currentPositionMs: number = 0
|
|
|
|
|
+ durationMs: number = 0
|
|
|
|
|
+ currentTimeText: string = DEFAULT_TIME_TEXT
|
|
|
|
|
+ durationTimeText: string = DEFAULT_TIME_TEXT
|
|
|
|
|
+ lyricLine1: string = MUSIC_CARD_EMPTY_TITLE
|
|
|
|
|
+ lyricLine2: string = MUSIC_CARD_EMPTY_ARTIST
|
|
|
|
|
+ hasLyric: boolean = false
|
|
|
|
|
+ filePath: string = ''
|
|
|
|
|
+ updatedAtMs: number = 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function createEmptyMusicCardSnapshot(): MusicCardSnapshot {
|
|
export function createEmptyMusicCardSnapshot(): MusicCardSnapshot {
|
|
@@ -179,45 +145,47 @@ export function resolveMusicCardLyricLines(
|
|
|
export function buildMusicCardBindingData(snapshot: MusicCardSnapshot): MusicCardBindingData {
|
|
export function buildMusicCardBindingData(snapshot: MusicCardSnapshot): MusicCardBindingData {
|
|
|
const source = snapshot || createEmptyMusicCardSnapshot()
|
|
const source = snapshot || createEmptyMusicCardSnapshot()
|
|
|
const lyricLines = resolveMusicCardLyricLines(source.lyricText, source.currentPositionMs)
|
|
const lyricLines = resolveMusicCardLyricLines(source.lyricText, source.currentPositionMs)
|
|
|
- const hasSong = Boolean(source.hasSong)
|
|
|
|
|
- const title =
|
|
|
|
|
- hasSong && isNonEmpty(source.title) ? source.title : MUSIC_CARD_EMPTY_TITLE
|
|
|
|
|
- const artist =
|
|
|
|
|
- hasSong && isNonEmpty(source.artist) ? source.artist : MUSIC_CARD_EMPTY_ARTIST
|
|
|
|
|
- const lyricLine1 =
|
|
|
|
|
- lyricLines.hasLyric && isNonEmpty(lyricLines.line1) ? lyricLines.line1 : title
|
|
|
|
|
- const lyricLine2 =
|
|
|
|
|
- lyricLines.hasLyric && isNonEmpty(lyricLines.line2) ? lyricLines.line2 : artist
|
|
|
|
|
- const hasLyric = lyricLines.hasLyric || Boolean(source.hasLyric)
|
|
|
|
|
- const currentTimeText = isNonEmpty(source.currentTimeText)
|
|
|
|
|
|
|
+ const data = new MusicCardBindingData()
|
|
|
|
|
+
|
|
|
|
|
+ data.hasSong = Boolean(source.hasSong)
|
|
|
|
|
+ data.title =
|
|
|
|
|
+ data.hasSong && isNonEmpty(source.title) ? source.title : MUSIC_CARD_EMPTY_TITLE
|
|
|
|
|
+ data.artist =
|
|
|
|
|
+ data.hasSong && isNonEmpty(source.artist) ? source.artist : MUSIC_CARD_EMPTY_ARTIST
|
|
|
|
|
+ data.coverPath = source.coverPath ?? ''
|
|
|
|
|
+ data.hasCoverImage = Boolean(source.hasCoverImage)
|
|
|
|
|
+ data.isPlaying = Boolean(source.isPlaying)
|
|
|
|
|
+ data.currentPositionMs = source.currentPositionMs ?? 0
|
|
|
|
|
+ data.durationMs = source.durationMs ?? 0
|
|
|
|
|
+ data.currentTimeText = isNonEmpty(source.currentTimeText)
|
|
|
? source.currentTimeText
|
|
? source.currentTimeText
|
|
|
: DEFAULT_TIME_TEXT
|
|
: DEFAULT_TIME_TEXT
|
|
|
- const durationTimeText = isNonEmpty(source.durationTimeText)
|
|
|
|
|
|
|
+ data.durationTimeText = isNonEmpty(source.durationTimeText)
|
|
|
? source.durationTimeText
|
|
? source.durationTimeText
|
|
|
: DEFAULT_TIME_TEXT
|
|
: DEFAULT_TIME_TEXT
|
|
|
- const coverPath = source.coverPath ?? ''
|
|
|
|
|
- const hasCoverImage = Boolean(source.hasCoverImage)
|
|
|
|
|
- const isPlaying = Boolean(source.isPlaying)
|
|
|
|
|
- const currentPositionMs = source.currentPositionMs ?? 0
|
|
|
|
|
- const durationMs = source.durationMs ?? 0
|
|
|
|
|
- const filePath = source.filePath ?? ''
|
|
|
|
|
- const updatedAtMs = source.updatedAtMs ?? 0
|
|
|
|
|
-
|
|
|
|
|
- return new MusicCardBindingData(
|
|
|
|
|
- title,
|
|
|
|
|
- artist,
|
|
|
|
|
- coverPath,
|
|
|
|
|
- hasCoverImage,
|
|
|
|
|
- hasSong,
|
|
|
|
|
- isPlaying,
|
|
|
|
|
- currentPositionMs,
|
|
|
|
|
- durationMs,
|
|
|
|
|
- currentTimeText,
|
|
|
|
|
- durationTimeText,
|
|
|
|
|
- lyricLine1,
|
|
|
|
|
- lyricLine2,
|
|
|
|
|
- hasLyric,
|
|
|
|
|
- filePath,
|
|
|
|
|
- updatedAtMs
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ data.filePath = source.filePath ?? ''
|
|
|
|
|
+ data.updatedAtMs = source.updatedAtMs ?? 0
|
|
|
|
|
+
|
|
|
|
|
+ let lyricLine1 = data.title
|
|
|
|
|
+ let lyricLine2 = data.artist
|
|
|
|
|
+ let hasLyric = false
|
|
|
|
|
+
|
|
|
|
|
+ if (lyricLines.hasLyric) {
|
|
|
|
|
+ lyricLine1 = lyricLines.line1
|
|
|
|
|
+ lyricLine2 = lyricLines.line2
|
|
|
|
|
+ hasLyric = true
|
|
|
|
|
+ } else if (
|
|
|
|
|
+ source.hasLyric &&
|
|
|
|
|
+ (isNonEmpty(source.lyricLine1) || isNonEmpty(source.lyricLine2))
|
|
|
|
|
+ ) {
|
|
|
|
|
+ lyricLine1 = isNonEmpty(source.lyricLine1) ? source.lyricLine1 : data.title
|
|
|
|
|
+ lyricLine2 = isNonEmpty(source.lyricLine2) ? source.lyricLine2 : data.artist
|
|
|
|
|
+ hasLyric = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ data.lyricLine1 = lyricLine1
|
|
|
|
|
+ data.lyricLine2 = lyricLine2
|
|
|
|
|
+ data.hasLyric = hasLyric
|
|
|
|
|
+
|
|
|
|
|
+ return data
|
|
|
}
|
|
}
|