diff --git a/common/compose-ui/src/androidMain/kotlin/com/shabinder/common/ui/Images.kt b/common/compose-ui/src/androidMain/kotlin/com/shabinder/common/ui/Images.kt new file mode 100644 index 00000000..d72bc715 --- /dev/null +++ b/common/compose-ui/src/androidMain/kotlin/com/shabinder/common/ui/Images.kt @@ -0,0 +1,36 @@ +package com.shabinder.common.ui + +import androidx.compose.foundation.Image +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.vectorResource + +@Composable +actual fun DownloadImageTick(modifier: Modifier){ + Image( + vectorResource(R.drawable.ic_tick), + "Download Done", + modifier + ) +} + +@Composable +actual fun DownloadImageError(modifier: Modifier){ + Image( + vectorResource(R.drawable.ic_error), + "Error! Cant Download this track", + modifier + ) +} + +@Composable +actual fun DownloadImageArrow(modifier: Modifier){ + Image( + vectorResource(R.drawable.ic_arrow), + "Start Download", + modifier + ) +} + +@Composable +actual fun DownloadAllImage() = vectorResource(R.drawable.ic_download_arrow) \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt index 18c6817f..bdb2023f 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt @@ -5,6 +5,7 @@ import com.arkivanov.decompose.ComponentContext import com.arkivanov.mvikotlin.core.store.StoreFactory import com.shabinder.common.* import com.shabinder.common.list.integration.SpotiFlyerListImpl +import com.shabinder.common.spotify.Source import com.shabinder.common.utils.Consumer import com.shabinder.database.Database import kotlinx.coroutines.flow.Flow @@ -43,7 +44,10 @@ interface SpotiFlyerList { object Finished : Output() } data class State( - val queryResult:PlatformQueryResult? = null, + val queryResult:PlatformQueryResult? = PlatformQueryResult( + "","", + "Loading","", emptyList(), + Source.Spotify), val link:String = "" ) } diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerListUi.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerListUi.kt index 28eef9ed..184f5d0f 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerListUi.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerListUi.kt @@ -1,12 +1,9 @@ package com.shabinder.common.list -import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.ExtendedFloatingActionButton -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material.* import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -14,6 +11,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -21,7 +19,7 @@ import androidx.compose.ui.unit.sp import com.shabinder.common.DownloadStatus import com.shabinder.common.Picture import com.shabinder.common.TrackDetails -import com.shabinder.common.ui.ImageLoad +import com.shabinder.common.ui.* import com.shabinder.spotiflyer.ui.SpotiFlyerTypography import com.shabinder.spotiflyer.ui.colorAccent import kotlinx.coroutines.CoroutineScope @@ -89,13 +87,13 @@ fun TrackCard( } when(track.downloaded){ DownloadStatus.Downloaded -> { - //Image(vectorResource(id = R.drawable.ic_tick)) + DownloadImageTick() } DownloadStatus.Queued -> { CircularProgressIndicator() } DownloadStatus.Failed -> { - //Image(vectorResource(id = R.drawable.ic_error)) + DownloadImageError() } DownloadStatus.Downloading -> { CircularProgressIndicator(progress = track.progress.toFloat()/100f) @@ -104,9 +102,9 @@ fun TrackCard( CircularProgressIndicator(progress = 100f,color = colorAccent) } DownloadStatus.NotDownloaded -> { - /*Image(vectorResource(id = R.drawable.ic_arrow), Modifier.clickable(onClick = { + DownloadImageArrow(Modifier.clickable(onClick = { downloadTrack() - }))*/ + })) } } } @@ -151,7 +149,7 @@ fun DownloadAllButton(onClick: () -> Unit, modifier: Modifier = Modifier) { ExtendedFloatingActionButton( text = { Text("Download All") }, onClick = onClick, - //icon = { Icon(imageVector = Image(R.drawable.ic_download_arrow),tint = Color.Black) }, + icon = { Icon(imageVector = DownloadAllImage(),tint = Color.Black) }, backgroundColor = colorAccent, modifier = modifier ) diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/ui/Images.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/ui/Images.kt new file mode 100644 index 00000000..18669e4d --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/ui/Images.kt @@ -0,0 +1,17 @@ +package com.shabinder.common.ui + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector + +@Composable +expect fun DownloadImageTick(modifier: Modifier = Modifier) + +@Composable +expect fun DownloadAllImage():ImageVector + +@Composable +expect fun DownloadImageError(modifier: Modifier = Modifier) + +@Composable +expect fun DownloadImageArrow(modifier: Modifier = Modifier) \ No newline at end of file diff --git a/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Actual.kt b/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Actual.kt index aa951174..9996c477 100644 --- a/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Actual.kt +++ b/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Actual.kt @@ -1,13 +1,37 @@ package com.shabinder.common.ui +import androidx.compose.foundation.Image import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.res.vectorXmlResource import com.shabinder.common.Picture +import java.awt.image.BufferedImage +import java.io.ByteArrayOutputStream +import javax.imageio.ImageIO @Composable actual fun ImageLoad( pic: Picture?, modifier: Modifier ){ - + if(pic == null) { + Image( + vectorXmlResource("common/compose-ui/src/main/res/drawable/music.xml"), + modifier + ) + } + else{ + Image( + org.jetbrains.skija.Image.makeFromEncoded( + toByteArray(pic.image) + ).asImageBitmap(), + modifier = modifier + ) + } +} +fun toByteArray(bitmap: BufferedImage) : ByteArray { + val baOs = ByteArrayOutputStream() + ImageIO.write(bitmap, "png", baOs) + return baOs.toByteArray() } \ No newline at end of file diff --git a/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Images.kt b/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Images.kt new file mode 100644 index 00000000..91dad9cd --- /dev/null +++ b/common/compose-ui/src/desktopMain/kotlin/com/shabinder/common/ui/Images.kt @@ -0,0 +1,34 @@ +package com.shabinder.common.ui + +import androidx.compose.foundation.Image +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.vectorXmlResource + +@Composable +actual fun DownloadImageTick(modifier: Modifier){ + Image( + vectorXmlResource("common/compose-ui/src/main/res/drawable/ic_tick.xml"), + modifier + ) +} + +@Composable +actual fun DownloadImageError(modifier: Modifier){ + Image( + vectorXmlResource("common/compose-ui/src/main/res/drawable/ic_error.xml"), + modifier + ) +} + +@Composable +actual fun DownloadImageArrow(modifier: Modifier){ + Image( + vectorXmlResource("common/compose-ui/src/main/res/drawable/ic_arrow.xml"), + modifier + ) +} + +@Composable +actual fun DownloadAllImage():ImageVector = vectorXmlResource("common/compose-ui/src/main/res/drawable/ic_download_arrow.xml") diff --git a/common/compose-ui/src/main/res/drawable/ic_arrow.xml b/common/compose-ui/src/main/res/drawable/ic_arrow.xml new file mode 100644 index 00000000..a426c154 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_arrow.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_download_arrow.xml b/common/compose-ui/src/main/res/drawable/ic_download_arrow.xml new file mode 100644 index 00000000..4a92ae81 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_download_arrow.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_error.xml b/common/compose-ui/src/main/res/drawable/ic_error.xml new file mode 100644 index 00000000..9ebd8a0e --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_error.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_gaana.xml b/common/compose-ui/src/main/res/drawable/ic_gaana.xml new file mode 100644 index 00000000..28d27c3c --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_gaana.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_heart.xml b/common/compose-ui/src/main/res/drawable/ic_heart.xml new file mode 100644 index 00000000..92f9beb0 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_heart.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_spotiflyer_logo.xml b/common/compose-ui/src/main/res/drawable/ic_spotiflyer_logo.xml new file mode 100644 index 00000000..bc68c3c7 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_spotiflyer_logo.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_spotify_logo.xml b/common/compose-ui/src/main/res/drawable/ic_spotify_logo.xml new file mode 100644 index 00000000..e773449a --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_spotify_logo.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_tick.xml b/common/compose-ui/src/main/res/drawable/ic_tick.xml new file mode 100644 index 00000000..47903522 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_tick.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_youtube.xml b/common/compose-ui/src/main/res/drawable/ic_youtube.xml new file mode 100644 index 00000000..728779f1 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_youtube.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/common/compose-ui/src/main/res/drawable/ic_youtube_music_logo.xml b/common/compose-ui/src/main/res/drawable/ic_youtube_music_logo.xml new file mode 100644 index 00000000..7e723917 --- /dev/null +++ b/common/compose-ui/src/main/res/drawable/ic_youtube_music_logo.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Dir.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Dir.kt index 4035cb1e..9c113a93 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Dir.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Dir.kt @@ -17,7 +17,7 @@ expect open class Dir( fun defaultDir(): String fun imageCacheDir(): String fun createDirectory(dirPath:String) - fun cacheImage(picture: Picture) + suspend fun cacheImage(picture: Picture) fun loadImage(url:String, cachePath:String = imageCacheDir() + getNameURL(url)):Picture? suspend fun clearCache() suspend fun saveFileWithMetadata(mp3ByteArray: ByteArray, path: String, trackDetails: TrackDetails) diff --git a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/Dir.kt b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/Dir.kt index 3ddccbe4..8d4e8775 100644 --- a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/Dir.kt +++ b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/Dir.kt @@ -2,6 +2,9 @@ package com.shabinder.common import co.touchlab.kermit.Kermit import com.mpatric.mp3agic.Mp3File +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import java.awt.image.BufferedImage import java.io.* import java.lang.Exception @@ -43,7 +46,7 @@ actual open class Dir actual constructor(private val logger: Kermit) { File(imageCacheDir()).deleteRecursively() } - actual fun cacheImage(picture: Picture) { + actual suspend fun cacheImage(picture: Picture) { try { val path = imageCacheDir() + picture.name @@ -137,8 +140,9 @@ actual open class Dir actual constructor(private val logger: Kermit) { result.width, result.height ) - - cacheImage(picture) + GlobalScope.launch(Dispatchers.IO) { //TODO Refactor + cacheImage(picture) + } picture } else null } catch (e: Exception) {