Skip to content

Commit

Permalink
fix: handle embedding lyrics into non-local songs
Browse files Browse the repository at this point in the history
Handle embedding lyrics into non-local songs by displaying a user-friendly error message.
Improve error handling
 for embedding lyrics and show specific error messages for different scenarios.
  • Loading branch information
BobbyESP committed Aug 14, 2024
1 parent abc4a29 commit 2dfbbed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 13 additions & 8 deletions app/src/main/java/pl/lambada/songsync/ui/screens/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,24 +401,29 @@ fun SharedTransitionScope.SearchScreen(
val lrc =
"[ti:${result.songName}]\n" + "[ar:${result.artistName}]\n" + "[by:$generatedUsingString]\n" + lyrics

val embeddedToFile = kotlin.runCatching {
kotlin.runCatching {
viewModel.embedLyricsInFile(
context,
filePath
?: throw NullPointerException("filePath is null"),
lrc
)
}

if (embeddedToFile.isFailure) {
}.onFailure { exception ->
val errorMessage = when(exception) {
is NullPointerException -> {
context.getString(R.string.embed_non_local_song_error)
}
else -> {
exception.message
?: context.getString(R.string.error)
}
}
Toast.makeText(
context,
embeddedToFile.exceptionOrNull()?.message
?: context.getString(R.string.error),
errorMessage,
Toast.LENGTH_LONG
).show()
return@Button
} else {
}.onSuccess {
Toast.makeText(
context,
context.getString(R.string.embedded_lyrics_in_file),
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@
<string name="include_translation">Include translation</string>
<string name="include_translation_summary">Include translated lyrics when getting song lyrics from Netease provider</string>
<string name="embed_lyrics_in_file">Embed lyrics to file</string>
<string name="embedded_lyrics_in_file">Lyrics has been embeded to the song file</string>
<string name="embedded_lyrics_in_file">Lyrics has been embedded to the song file</string>
<string name="embed_non_local_song_error">You tried to embed the lyrics to a non-local file. Aborting operation.</string>
</resources>

0 comments on commit 2dfbbed

Please sign in to comment.