Skip to content

Commit

Permalink
- Moved almost every string to a string resource
Browse files Browse the repository at this point in the history
- 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
BobbyESP committed Jun 24, 2023
1 parent 8f464ef commit aa45a8a
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 223 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
//kotlinx serialization plugin
kotlin("plugin.serialization")
}

val spotifyClientID = gradleLocalProperties(rootDir).getProperty("spotify_client_id")!!
Expand Down Expand Up @@ -90,4 +92,6 @@ dependencies {
implementation("androidx.compose.material:material-icons-extended:1.5.0-beta01")
implementation("com.google.accompanist:accompanist-permissions:0.31.3-beta")
implementation("com.google.accompanist:accompanist-coil:0.15.0")
//kotlinx serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
}
4 changes: 2 additions & 2 deletions app/src/main/java/pl/lambada/songsync/data/Song.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.net.Uri

data class Song(
val id: Long?,
val title: String?,
val artist: String?,
val title: String? = "Unknown",
val artist: String? = "Unknown",
val imgUri: Uri?,
val filePath: String?,
val fileName: String?
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/pl/lambada/songsync/data/SongInfo.kt
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 app/src/main/java/pl/lambada/songsync/ui/components/SongCard.kt
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)
}
}
}
}
Loading

0 comments on commit aa45a8a

Please sign in to comment.