-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
440 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
app/src/main/java/player/phonograph/model/lyrics/LyricsCursor.kt
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
app/src/main/java/player/phonograph/model/lyrics/LyricsInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2022~2023 chr_56 | ||
*/ | ||
|
||
package player.phonograph.model.lyrics | ||
|
||
import player.phonograph.model.Song | ||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
|
||
@Parcelize | ||
data class LyricsInfo( | ||
val linkedSong: Song, | ||
private val lyricsList: ArrayList<AbsLyrics>, | ||
private val activatedLyricsNumber: Int, | ||
) : Parcelable, List<AbsLyrics> by lyricsList { | ||
|
||
|
||
fun firstLrcLyrics(): LrcLyrics? = findFirst<LrcLyrics>() | ||
fun firstTextLyrics(): TextLyrics? = findFirst<TextLyrics>() | ||
fun allLyricsFrom(source: LyricsSource): List<AbsLyrics> = lyricsList.filter { it.source == source } | ||
fun firstLyricsFrom(source: LyricsSource): AbsLyrics? = allLyricsFrom(source).firstOrNull() | ||
fun availableSources(): Set<LyricsSource> = lyricsList.map { it.source }.toSet() | ||
val activatedLyrics: AbsLyrics? get() = lyricsList.getOrNull(activatedLyricsNumber) | ||
|
||
fun isActive(index: Int) = index == activatedLyricsNumber | ||
|
||
private inline fun <reified L> findFirst(): L? { | ||
for (lyric in lyricsList) { | ||
if (lyric is L) return lyric | ||
} | ||
return null | ||
} | ||
|
||
fun createAmended(absLyrics: AbsLyrics): LyricsInfo = insect(this, absLyrics) | ||
|
||
fun replaceActivated(index: Int): LyricsInfo = setActive(this, index) | ||
fun replaceActivated(lyrics: AbsLyrics): LyricsInfo? = setActive(this, lyrics) | ||
|
||
companion object { | ||
val EMPTY = LyricsInfo(Song.EMPTY_SONG, ArrayList(), -1) | ||
|
||
private fun insect(old: LyricsInfo, newLyrics: AbsLyrics): LyricsInfo = | ||
LyricsInfo( | ||
old.linkedSong, | ||
ArrayList(old.lyricsList).also { it.add(newLyrics) }, | ||
old.activatedLyricsNumber | ||
) | ||
|
||
private fun setActive(old: LyricsInfo, index: Int): LyricsInfo = | ||
LyricsInfo( | ||
old.linkedSong, | ||
old.lyricsList, | ||
index | ||
) | ||
|
||
private fun setActive(old: LyricsInfo, lyrics: AbsLyrics): LyricsInfo? { | ||
var index = -1 | ||
for ((i, l) in old.lyricsList.withIndex()) { | ||
if (l === lyrics) { | ||
index = i | ||
} | ||
} | ||
return if (index > -1) setActive(old, index) else null | ||
} | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
app/src/main/java/player/phonograph/model/lyrics/LyricsList.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.