-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Moved almost every string to a string resource
- Moved UI state and Query state from String declaration to enum classes - Added Kotlinx.serialization - Added saver to Song Info (you can choose how to save things with rememberSaveable)
- Loading branch information
Showing
10 changed files
with
438 additions
and
223 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
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 |
---|---|---|
@@ -1,13 +1,33 @@ | ||
package pl.lambada.songsync.data | ||
|
||
import androidx.compose.runtime.saveable.Saver | ||
import androidx.compose.runtime.saveable.SaverScope | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
/* | ||
Data class for storing song information | ||
Used both for local and remote songs, | ||
the only difference is that local songs have songLink set to null | ||
*/ | ||
@Serializable | ||
data class SongInfo( | ||
var songName: String? = null, | ||
var artistName: String? = null, | ||
var songLink: String? = null, | ||
var albumCoverLink: String? = null, | ||
) | ||
|
||
//SongInfo saver | ||
//Used for saving song info with rememberSaveable | ||
object SongInfoSaver: Saver<SongInfo, String> { | ||
override fun restore(value: String): SongInfo { | ||
return Json.decodeFromString(value) | ||
} | ||
|
||
override fun SaverScope.save(value: SongInfo): String { | ||
return Json.encodeToString(value) | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/pl/lambada/songsync/ui/components/SongCard.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,55 @@ | ||
package pl.lambada.songsync.ui.components | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.OutlinedCard | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import coil.compose.rememberAsyncImagePainter | ||
import pl.lambada.songsync.ui.common.MarqueeText | ||
|
||
@Composable | ||
fun SongCard( | ||
modifier: Modifier = Modifier, | ||
songName: String, | ||
artists: String, | ||
coverUrl: String, | ||
) { | ||
OutlinedCard( | ||
shape = RoundedCornerShape(10.dp), | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(8.dp) | ||
) { | ||
val painter = rememberAsyncImagePainter(model = coverUrl) | ||
Row(modifier = Modifier.height(72.dp)) { | ||
Image( | ||
painter = painter, | ||
contentDescription = "Album cover", | ||
modifier = Modifier | ||
.height(72.dp) | ||
.aspectRatio(1f), | ||
) | ||
Spacer(modifier = Modifier.width(2.dp)) | ||
Column( | ||
modifier = Modifier.padding(12.dp), | ||
verticalArrangement = Arrangement.Top | ||
) { | ||
MarqueeText(text = songName, fontSize = 18.sp) | ||
Spacer(modifier = Modifier.weight(1f)) | ||
MarqueeText(text = artists, fontSize = 14.sp) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.