From 189441111bc5de7bfe3a8f0b1de7df96ef2a4156 Mon Sep 17 00:00:00 2001 From: shabinder Date: Tue, 23 Feb 2021 22:35:11 +0530 Subject: [PATCH] Ui & TokenStore Fixes --- .../com/shabinder/common/list/SpotiFlyerListUi.kt | 4 ++++ .../list/store/SpotiFlyerListStoreProvider.kt | 13 ++++--------- .../com/shabinder/common/models/DownloadObject.kt | 5 ++--- .../com/shabinder/common/database/TokenDB.sq | 9 ++++----- .../kotlin/com/shabinder/common/di/AndroidDir.kt | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) 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 210b361e..357dc98e 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 @@ -69,6 +69,10 @@ fun TrackCard( downloadTrack:()->Unit, loadImage:suspend (String)-> ImageBitmap? ) { + /*val status = remember { mutableStateOf(track.downloaded.name()) } + LaunchedEffect(track.downloaded.name()){ + status.value = track.downloaded.name() + }*/ Row(verticalAlignment = Alignment.CenterVertically,modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp)) { ImageLoad( {loadImage(track.albumArtURL)}, diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt index f86e834b..a3c2a096 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt @@ -1,7 +1,5 @@ package com.shabinder.common.list.store -import androidx.compose.runtime.mutableStateListOf -import androidx.compose.runtime.snapshots.SnapshotStateList import com.arkivanov.mvikotlin.core.store.* import com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor import com.shabinder.common.database.getLogger @@ -16,9 +14,7 @@ import com.shabinder.common.models.PlatformQueryResult import com.shabinder.common.models.TrackDetails import com.shabinder.common.ui.showPopUpMessage import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.collectLatest -import org.koin.ext.scope internal class SpotiFlyerListStoreProvider( private val dir: Dir, @@ -70,16 +66,15 @@ internal class SpotiFlyerListStoreProvider( else downloadTracks(finalList,fetchQuery.youtubeMusic::getYTIDBestMatch,dir::saveFileWithMetadata) val list = intent.trackList.map { - if (it.downloaded == DownloadStatus.NotDownloaded) { - it.downloaded = DownloadStatus.Queued - } + if (it.downloaded == DownloadStatus.NotDownloaded) + return@map it.copy(downloaded = DownloadStatus.Queued) it } dispatch(Result.UpdateTrackList(list.updateTracksStatuses(downloadProgressFlow.replayCache.getOrElse(0){ hashMapOf()}))) } is Intent.StartDownload -> { downloadTracks(listOf(intent.track),fetchQuery.youtubeMusic::getYTIDBestMatch,dir::saveFileWithMetadata) - dispatch(Result.UpdateTrackItem(intent.track.apply { downloaded = DownloadStatus.Queued })) + dispatch(Result.UpdateTrackItem(intent.track.copy(downloaded = DownloadStatus.Queued))) } is Intent.RefreshTracksStatuses -> queryActiveTracks() } @@ -108,7 +103,7 @@ internal class SpotiFlyerListStoreProvider( for(newTrack in map){ titleList.indexOf(newTrack.key).let { position -> if(position != -1){ - updatedList.getOrNull(position)?.apply { downloaded = newTrack.value }?.also { updatedTrack -> + updatedList.getOrNull(position)?.copy(downloaded = newTrack.value)?.also { updatedTrack -> updatedList[position] = updatedTrack logger.d("$position) ${updatedTrack.downloaded} - ${updatedTrack.title}","List Store Track Update") } diff --git a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt index bf205b97..0c0b7fc5 100644 --- a/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt +++ b/common/data-models/src/commonMain/kotlin/com/shabinder/common/models/DownloadObject.kt @@ -35,10 +35,9 @@ data class TrackDetails( var albumArtPath: String, var albumArtURL: String, var source: Source, - var downloaded: DownloadStatus = DownloadStatus.NotDownloaded, - var progress: Int = 2,//2 for visual progress bar hint + val downloaded: DownloadStatus = DownloadStatus.NotDownloaded, var outputFilePath: String, - var videoID:String? = null + var videoID:String? = null, ):Parcelable diff --git a/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq b/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq index 04cb78c2..99dbbebe 100644 --- a/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq +++ b/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq @@ -1,16 +1,15 @@ CREATE TABLE IF NOT EXISTS Token ( - tokenIndex INTEGER NOT NULL DEFAULT 0 PRIMARY KEY ON CONFLICT REPLACE, + tokenIndex INTEGER NOT NULL PRIMARY KEY ON CONFLICT REPLACE, accessToken TEXT NOT NULL, expiry INTEGER NOT NULL ); add: -INSERT OR REPLACE INTO Token (accessToken,expiry) -VALUES (?,?); +INSERT OR REPLACE INTO Token (tokenIndex,accessToken,expiry) +VALUES (0,?,?); select: -SELECT * -FROM Token +SELECT * FROM Token WHERE tokenIndex = 0; clear: diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt index 8a015383..4dd7708d 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidDir.kt @@ -88,7 +88,7 @@ actual class Dir actual constructor( "-i ${m4aFile.absolutePath} -y -b:a 160k -acodec libmp3lame -vn ${m4aFile.absolutePath.substringBeforeLast('.') + ".mp3"}" ){ _, returnCode -> when (returnCode) { - Config.RETURN_CODE_SUCCESS -> { + Config.RETURN_CODE_SUCCESS -> { //FFMPEG task Completed logger.d{ "Async command execution completed successfully." } scope.launch {