Skip to content

Commit

Permalink
Merge branch 'kerollosy-musixmatch'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambada10 committed Nov 28, 2024
2 parents b72e3a2 + b324b63 commit dcd538b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class QuickLyricsSearchViewModel(
userSettingsController.selectedProvider,
userSettingsController.includeTranslation,
userSettingsController.multiPersonWordByWord,
userSettingsController.syncedMusixmatch
userSettingsController.unsyncedFallbackMusixmatch
)

private fun updateScreenState(screenState: ScreenState<SongInfo>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UserSettingsController(private val dataStore: DataStore<Preferences>) {
var multiPersonWordByWord by mutableStateOf(dataStore.get(multiPersonWordByWordKey, true))
private set

var syncedMusixmatch by mutableStateOf(dataStore.get(syncedMusixmatchKey, true))
var unsyncedFallbackMusixmatch by mutableStateOf(dataStore.get(unsyncedFallbackMusixmatchKey, true))
private set

var pureBlack by mutableStateOf(dataStore.get(pureBlackKey, false))
Expand Down Expand Up @@ -97,9 +97,9 @@ class UserSettingsController(private val dataStore: DataStore<Preferences>) {
multiPersonWordByWord = to
}

fun updateSyncedMusixmatch(to: Boolean) {
dataStore.set(syncedMusixmatchKey, to)
syncedMusixmatch = to
fun updateUnsyncedFallbackMusixmatch(to: Boolean) {
dataStore.set(unsyncedFallbackMusixmatchKey, to)
unsyncedFallbackMusixmatch = to
}

fun updateDisableMarquee(to: Boolean) {
Expand Down Expand Up @@ -144,7 +144,7 @@ private val blacklistedFoldersKey = stringPreferencesKey("blacklist")
private val hideLyricsKey = booleanPreferencesKey("hide_lyrics")
private val includeTranslationKey = booleanPreferencesKey("include_translation")
private val multiPersonWordByWordKey = booleanPreferencesKey("multi_person_word_by_word")
private val syncedMusixmatchKey = booleanPreferencesKey("synced_lyrics")
private val unsyncedFallbackMusixmatchKey = booleanPreferencesKey("unsynced_lyrics_fallback")
private val disableMarqueeKey = booleanPreferencesKey("marquee_disable")
private val pureBlackKey = booleanPreferencesKey("pure_black")
private val sdCardPathKey = stringPreferencesKey("sd_card_path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LyricsProviderService {
// TODO providers could be a sealed interface to include such parameters
includeTranslationNetEase: Boolean = false,
multiPersonWordByWord: Boolean = false,
syncedMusixmatch: Boolean = true
unsyncedFallbackMusixmatch: Boolean = true
): String? {
return when (provider) {
Providers.SPOTIFY -> SpotifyLyricsAPI().getSyncedLyrics(songLink!!, version)
Expand All @@ -109,7 +109,8 @@ class LyricsProviderService {
)

Providers.MUSIXMATCH -> MusixmatchAPI().getLyrics(
musixmatchSongInfo, syncedMusixmatch
musixmatchSongInfo,
unsyncedFallbackMusixmatch
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class MusixmatchAPI {
/**
* Returns the lyrics.
* @param songInfo The SongInfo of the song from search results.
* @param preferUnsynced Flag to prefer unsynced lyrics when synced lyrics are not available.
* @return The lyrics as a string or null if the lyrics were not found.
*/
fun getLyrics(songInfo: SongInfo?, synced: Boolean = true): String? {
return if(synced) songInfo?.syncedLyrics
else songInfo?.unsyncedLyrics
fun getLyrics(songInfo: SongInfo?, preferUnsynced: Boolean = true): String? {
return songInfo?.syncedLyrics ?: if (preferUnsynced) songInfo?.unsyncedLyrics else null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class HomeViewModel(
provider = userSettingsController.selectedProvider,
includeTranslationNetEase = userSettingsController.includeTranslation,
multiPersonWordByWord = userSettingsController.multiPersonWordByWord,
syncedMusixmatch = userSettingsController.syncedMusixmatch
unsyncedFallbackMusixmatch = userSettingsController.unsyncedFallbackMusixmatch
)
} catch (e: Exception) {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LyricsFetchViewModel(
userSettingsController.selectedProvider,
userSettingsController.includeTranslation,
userSettingsController.multiPersonWordByWord,
userSettingsController.syncedMusixmatch
userSettingsController.unsyncedFallbackMusixmatch
)

fun loadSongInfo(context: Context, tryingAgain: Boolean = false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ fun SettingsScreen(

item {
SyncedLyricsSwitch(
selected = userSettingsController.syncedMusixmatch,
onToggle = { userSettingsController.updateSyncedMusixmatch(it) }
selected = userSettingsController.unsyncedFallbackMusixmatch,
onToggle = { userSettingsController.updateUnsyncedFallbackMusixmatch(it) }
)
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
<string name="offset">Offset</string>
<string name="song_path">Show song path</string>
<string name="song_path_description">Show the path of a song file on song list</string>
<string name="synced_lyrics">Get Synced Lyrics</string>
<string name="synced_lyrics_summary">Toggle to switch between synced and unsynced lyrics from Musixmatch.</string>
<string name="synced_lyrics">Get Unsynced Lyrics</string>
<string name="synced_lyrics_summary">Toggle to get unsynced lyrics from Musixmatch when synced lyrics aren\'t found.</string>
<string name="title">Title</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
Expand Down

0 comments on commit dcd538b

Please sign in to comment.